I'm a newbie at numpy, but I was of that notion that you should not iterate over numpy arrays as this defies the purpose of numpy.
I'm trying to perform elementwise operations on a numpy array, but I don't understand the syntax apparantly:
Code:
for line in fidNNC:
temp = line.strip().split()
temp.insert(0,0)
CC.append(temp[0:7])
fidNNC.close()
NNC = np.array(CC)
del(CC)
inds = np.arange(len(NNC))[ NNC[:,4]-1 == NNC[:,1] ]
NNCX = NNC[inds,:]
inds = np.arange(len(NNC))[ NNC[:,5]-1 == NNC[:,2] ]
NNCY = NNC[inds,:]
The file fidNNC contains about a million rows and ten columns of ints.
Error message:
inds = np.arange(len(NNC))[ NNC[:,4]-1 == NNC[:,1] ]
TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'int'
How do I subtract 1 from each and every one element of NNC[:,4] and NNC[:,5] without iterating?
Thanks in advance,
Daniel