Python Forum
' List[ Conditional statement ] ' What is this code supposed to do.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
' List[ Conditional statement ] ' What is this code supposed to do.
#1
What does X[y==yi] (Line: 18) do ?

This is the full code:

from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
import numpy as np

iris = load_iris()

X = iris.data[:, [0, 2]]
#print(iris.data)

y = iris.target

def plot_scatter(X,y):
    
    colors = ["red","blue","black","yellow","green","purple","orange"]
    markers = ('s', 'x', 'o', '^', 'v')
    
    for i, yi in enumerate(np.unique(y)):
        Xi = X[y==yi]
        print(Xi)
        plt.scatter(Xi[:,0], Xi[:,1], color=colors[i], marker=markers[i], label=yi) 
   
    plt.xlabel('X label')
    plt.ylabel('Y label')
    plt.legend(loc='upper left')
    
plot_scatter(X,y)
Reply


Messages In This Thread
' List[ Conditional statement ] ' What is this code supposed to do. - by Arindam - Nov-30-2018, 04:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Conditional If Statement: If value contains string then set another column equal to s Jack_Sparrow 2 4,923 Jun-15-2018, 03:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020