I encounter the following errors when converting an integer to a numpy array:
a = 150
b = np.array(a)
b[0]
*** IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
I expect the output of b[0] is 150, but get the IndexError. Why?
(). you can usenp.array([a])if you want to define a one dimentional array.bisarray(150)instead ofarray([150]). What does it mean?b[()].b[()]indexes the 0d array with a 0 element tuple.np.array([150])[0]indexes with a 1d array with 1 index.b.item()is another way of getting the element (from either).