This is a really simple question, but I didnt find the answer. How to call an element in an numpy array?
import numpy as np
arr = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print arr(0,0)
The code above doesn't work.
This is a really simple question, but I didnt find the answer. How to call an element in an numpy array?
import numpy as np
arr = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print arr(0,0)
The code above doesn't work.
If you are using numpy and your array is an np.array of np.array elements like:
A = np.array([np.array([10,11,12,13]), np.array([15,16,17,18]), np.array([19,110,111,112])])
and you want to access the inner elements (like 10,11,12 13,14.......) then use:
A[0][0] instead of A[0,0]
For example:
>>> import numpy as np
>>>A = np.array([np.array([10,11,12,13]), np.array([15,16,17,18]), np.array([19,110,111,112])])
>>> A[0][0]
>>> 10
>>> A[0,0]
>>> Throws ERROR
(P.S.: Might be useful when using numpy.array_split())
Also, you could try to use ndarray.item(), for example, arr.item((0, 0))(rowid+colid to index) or arr.item(0)(flatten index), its doc https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.item.html
Use numpy. array. flatten() to convert a 2D NumPy array into a 1D array
print(array_2d)
array_1d = array_2d. flatten() flatten array_2d
print(array_1d)