I am trying to refactor procedural code of a numpy 3d array into it's vectorized equivalent and the results are not matching .
import numpy as np
arr = np.empty((16,73,144))
boolArray = np.zeros((14,73,144))
for k in range(0,16):
for j in range(0,73):
for i in range(0,144):
if (k == 0):
doSomething():
else if (k == 15):
doSomething():
else:
if (arr[k+1,j,i] == arr[k-1,j,i]):
boolArray[k,j,i] = True
The vectorized counterpart -
# isArrEqual is a boolean array of identical shape to boolArray
isArrEqual = (arr[2:,:,:] == arr[0:-2,:,:])
In my real data I get 6000 true entries for the procedural code and no trues at all in the vectorized counterpart.
Where I am going wrong ?
arr = np.empty(16,73,144)should bearr = np.empty((16,73,144)). Same forboolArray