python - Not able to understand the code in Matplot lib -


I know that the following code is a scattered plot, with its own markers. I am not able to understand the converter function.

The normal defunition of the converter function: A mapping for a function is the column number that will change that column to float. For example, if column 0 is a date string: converters = {0: datestr2num}. Converters can also be used to provide a default value for wrong data (but also see genomom): converters = {3: lambda s: float (s. Crypt) or 0)}. Default: None.

But I am not able to understand what it does in the following code; Does read_label function?

  NMP import as import matplotlib.pyplot plt label_list = (b'Iris-setosa ', b'Iris-versicolor', b'Iris-virginica ',), Read_label (Label): return_label.index (label) data = np.loadtxt ('iris.data.txt', delimiter = ',', converters = {4: read_label}) marker_set = ('^', 'X', ' .), For calculating (marker_set) in the marker: data_subset = numpy.asarray ([x for x in x if x [4] == i]) plt.scatter (data_subset [, 0], data_subset [ :, 1], color = 'k', marker = marker) plt.show ()  

The iris.data.txt file contains the following data:

4.6,3.2,1.4,0.2, Iris-Sashosha 5.3,3.7,1,5,0.2, Iris-Setosa 5.0,3.3,1.4,0.2, Irri -Sashosa 7.0.3.2.4.7.1.4, Iris-Virikolor 6.4.3.2,

code> a small test With the program:

  label_list = (b'Iris-setosa ', b'Iris-versicolor', b'Iris-vir Print_label (label): return label_list.index (label) print read_label ("Iris-Setosa") printed read_label ("Iris-Vernicular") printed read_label ("iris-virginica")  

Output:

  0 1 2  

Alternatively, you: It gives a list indicator of the given element.

Note that if you do not ask for the element in the list, you get the ValueError . You would like to use find in that situation.


Comments