I loaded a text file containing a two column matrix (e.g. below)
[ 1 3 2 4 3 5 2 0]
My calculation is just to sum each row i.e. 1+3, 2+4, 3+5 and 2+0. I am using the below code:
data=np.loadtxt(fname="textfile.txt")## to load the above two column xy= data for XY in xy: i=0 Z=XY(i,0)+XY(i,1) i=i+1 print (Z)
But I received an error saying numpy.ndarray object is not callable
. Why does this happen? How can I do this simple calculation? Thanks.
The ndarray object consists of contiguous one-dimensional segment of computer memory, combined with an indexing scheme that maps each item to a location in the memory block. The memory block holds the elements in a row-major order (C style) or a column-major order (FORTRAN or MatLab style).
NumPy arrays are typed arrays of fixed size. Python lists are heterogeneous and thus elements of a list may contain any object type, while NumPy arrays are homogenous and can contain object of only one type.
numpy. array is just a convenience function to create an ndarray ; it is not a class itself. You can also create an array using numpy. ndarray , but it is not the recommended way.
A numpy array is a sequence, but it is not a Sequence as it is not registered as a subclass of Sequence.
The error TypeError: 'numpy.ndarray' object is not callable means that you tried to call a numpy array as a function.
Use
Z=XY[0]+XY[1]
Instead of
Z=XY(i,0)+XY(i,1)
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