Why are numpy array called homogeneous?

Viewed 44

Why are numpy arrays called homogeneous when you can have elements of different type in the same numpy array like this?

np.array([1,2,3,4,"a"])

I understand that I cannot perform some types of broadcasting operations like I cannot perform np1*4 here and it results in an error. but my question really is when it can have elements of different types, why it is called homogeneous?

1 Answers

Numpy automatically converts them to most applicable datatype.

e.g.,

>>> np.array([1,2,3,4,"a"]).dtype.type
numpy.str_

In short this means all elements are of string.

>>> np.array([1,2,3,4]).dtype.type
numpy.int64
Related