So, this is something, that should be pretty easy, but it seems to take an enormous amount of time for me: I have a numpy array with only two values (example 0 and 255) and I want to invert the matrix in that way, that all values swap (0 becomes 255 and vice versa). The matrices are about 2000³ entries big, so this is serious work! I first tried the numpy.invert method, which is not exactly what I expected. So I tried to do that myself by "storing" the values and then override them:
for i in range(array.length):
array[i][array[i]==255]=1
array[i][array[i]==0]=255
array[i][array[i]==1]=0
which is behaving as expected, but taking a long time (I guess due to the for loop?). Would that be faster if I implement that as a multithreaded calculation, where every thread "inverts" a smaller sub-array? Or is there another way of doing that more conveniently?
arrayfor the name of your array: NumPy users expectarrayto meannumpy.array. Furthermore, when you paste code into a shell afterfrom numpy import *(orfrom pylab import *), your variable shadows NumPy'sarray.