the different fields of the records. And “formats” indicates the formats of the different fields. As we discussed, the first four fields contain floating point numbers, and the fifth field contains strings. Please note that “|S15” indicates the format of a string that is 15 bytes in length. The “|” symbol here refers that the byte order flag is not applicable.
Finally, we are printing the shape of the ndarray and the ndarray. Please note that the ndarray returned by the numpy.loadtxt() function contains 150 array-like objects. And each record is stored in each object. In other words, each object is a tuple that contains five fields – sepal length, sepal width, petal length, petal width, and species. (What is a tuple in Python, and when do we use tuples instead of lists?)
The output of the above program will be:
(150,) [(5.1, 3.5, 1.4, 0.2, b'setosa') (4.9, 3. , 1.4, 0.2, b'setosa') (4.7, 3.2, 1.3, 0.2, b'setosa') (4.6, 3.1, 1.5, 0.2, b'setosa') (5. , 3.6, 1.4, 0.2, b'setosa') (5.4, 3.9, 1.7, 0.4, b'setosa') (4.6, 3.4, 1.4, 0.3, b'setosa') (5. , 3.4, 1.5, 0.2, b'setosa') (4.4, 2.9, 1.4, 0.2, b'setosa') (4.9, 3.1, 1.5, 0.1, b'setosa') (5.4, 3.7, 1.5, 0.2, b'setosa') (4.8, 3.4, 1.6, 0.2, b'setosa') (4.8, 3. , 1.4, 0.1, b'setosa') (4.3, 3. , 1.1, 0.1, b'setosa') (5.8, 4. , 1.2, 0.2, b'setosa') (5.7, 4.4, 1.5, 0.4, b'setosa') (5.4, 3.9, 1.3, 0.4, b'setosa') (5.1, 3.5, 1.4, 0.3, b'setosa') ...






0 Comments