When I create an empty numpy array using foo = np.empty(1) the resulting array contains a float64:
>>> foo = np.empty(1)
>>> foo
array([ 0.])
>>> type(foo[0])
<type 'numpy.float64'>
Why doesn't it just return array([])?
You didn't read the documentation, which says:
Return a new array of given shape and type, without initializing entries.
empty has nothing to do with creating an array that is "empty" in the sense of having no elements. It just means the array doesn't have its values initialized (i.e., they are unpredictable and depend on whatever happens to be in the memory allocated for the array).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With