The problem is what you are assigning using the mask. Not knowing what's inside g1, g2, g3 and g4 it's quite difficult to understand what you are doing, but probably
tau*(g1+g2-g3+g4)
is a vector of two dimension. Instead you need to assign a single value. For example, if you change your assignment in this way, it will probably work:
g1_coll[obstacle==0]=(tau*(g1+g2-g3+g4))[0]
g2_coll[obstacle==0]=(tau*(g1+g2+g3-g4))[0]
g3_coll[obstacle==0]=(tau*(-g1+g2+g3+g4))[0]
g4_coll[obstacle==0]=(tau*(g1-g2+g3+g4))[0]
or, if it is not working:
g1_coll[obstacle==0]=(tau*(g1+g2-g3+g4))[0][0]
g2_coll[obstacle==0]=(tau*(g1+g2+g3-g4))[0][0]
g3_coll[obstacle==0]=(tau*(-g1+g2+g3+g4))[0][0]
g4_coll[obstacle==0]=(tau*(g1-g2+g3+g4))[0][0]
But before doing anything you should understand what's inside your input (tau*(g1+g2-g3+g4)
).
My guess is that probably g1, g2, g3, and g4 are vectors of two dimensions
With this example I can reproduce your error:
import numpy as np
import random
my_matrix = np.random.rand(4)
print(my_matrix)
my_boolean_array = my_matrix < 0.5
print(my_boolean_array)
my_matrix[my_boolean_array] = [[0, 0]] # two dimensions array! not a single value. This will not work
print(my_matrix)
Try to print the value inside
print(tau*(g1+g2-g3+g4))
g1_coll
andobstacle
to make the question more understandable