Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python error, "NumPy boolean array indexing assignment requires a 0 or 1-dimensional input, input has 2 dimensions"

Tags:

python

numpy

I'm kinda new to python, currently working on a project and getting this error with this lines of code.

    g1_coll[obstacle==0]=tau*(g1+g2-g3+g4)
    g2_coll[obstacle==0]=tau*(g1+g2+g3-g4)
    g3_coll[obstacle==0]=tau*(-g1+g2+g3+g4)
    g4_coll[obstacle==0]=tau*(g1-g2+g3+g4)

can anyone help me understand this?

like image 485
jsp Avatar asked Aug 31 '26 06:08

jsp


1 Answers

I Assume the error you are getting is because all of your arrays are 2-dimensional. I suggest you try using numpy.putmask(matrix, mask, new_matrix_values)

For instance

    mask = (obstacle == 0)
    numpy.putmask(g1_coll, mask, tau*(g1+g2-g3+g4))
    numpy.putmask(g2_coll, mask, tau*(g1+g2+g3-g4))
    numpy.putmask(g3_coll, mask, tau*(-g1+g2+g3+g4))
    numpy.putmask(g4_coll, mask, tau*(g1-g2+g3+g4))
like image 100
melqkiades Avatar answered Sep 02 '26 19:09

melqkiades



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!