I actually solved it in another way.
I made an empty array and used the coordinates to just put the values in the new array. If someone is interested i post the code below:
<pre lang="Python"><pre>##########################################
import cv2
# Taking the first image of the data
image = series_copy2[0,:,:]
# Mean total background of the image
print('Mean total background = ' +str(np.mean(image)) + ' counts.')
# Threshold for background removal
threshold =15
# Setting all pixels below a threshold to zero to remove the background
image[image[:,:] < threshold] = 0
image[image[:,:]>threshold]=1
# Plotting the result for checking
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
plt.tight_layout()
im = plt.imshow(image, interpolation = 'nearest')
np.transpose(np.nonzero(image))
nz_arrays=np.transpose(np.nonzero(image))
empty = np.zeros(shape=(256,256))
for i,j in nz_arrays:
empty[i,j]=series[0,i,j]
# Plotting the result for checking
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
plt.tight_layout()
im = plt.imshow(empty, interpolation = 'nearest')