Just like list in python where [1,"hello", {"python": 10}] it can have all different types within, can numpy array have this as well?
when numpyarray.dtype => dtype('float64') is it implying all elements are of type float?
-
Why do you want an array with mixed data types? Why not stick with a list?hpaulj– hpaulj2019年03月03日 17:18:03 +00:00Commented Mar 3, 2019 at 17:18
-
I just wanted to know. Since incoming data can be of many different types I wanted to know what happens when I convert it to numpy arrayhaneulkim– haneulkim2019年03月03日 17:21:46 +00:00Commented Mar 3, 2019 at 17:21
2 Answers 2
Yes, if you use numpy structured arrays, each element of the array would be a "structure", and the fields of the structure can have different datatypes.
The answer to your second question is yes. When the dtype attribute shows a value of float64, it means each element is a float64
Comments
From the docs:
dtype : data-type, optional
The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. This argument can only be used to ‘upcast’ the array. For downcasting, use the .astype(t) method.
So if you set dtype as float64, everything needs to be a float. You can mix types, but then you can't set it as a mismatching type. It will use a type that will fit all data, like a string for example in the case of array(['1', 'Foo', '3.123']).