I am taking an online course, and the following supposedly demonstrates that "NumPy arrays: contain only one type":
In [19]: np.array([1.0, "is", True])
Out[19]:
array(['1.0', 'is', 'True'],
dtype='<U32')
At first, I thought that the output was a form of error message, but this is not confirmed by a web search. In fact, I haven't come across an explanation....can anyone explain how to interpret the output?
Afternote: After reviewing the answers, the dtype
page, and the numpy.array()
page, it seems that dtype='<U32'
would be more accurately described as dtype('<U32')
. Is this correct? I seems so to me, but I'm a newbie, and even the numpy.array()
page assigns a string to the dtype
parameter rather than an actual dtype
object.
Also, why does '<U32'
specify a 32-character string when all of the elements are much shorter strings?