how to modify a 2D numpy array at specific locations without a loop?

前端 未结 4 1453
迷失自我
迷失自我 2020-12-09 15:01

I have a 2D numpy array and I have a arrays of rows and columns which should be set to a particular value. Lets consider the following example

 a = array([[1         


        
4条回答
  •  借酒劲吻你
    2020-12-09 15:45

    First off, your description of the "correct" array doesn't match the columns and rows you specify...

    To get your "correct" array, you'd do this:

    a[:2, 2] = 0
    

    To modify the second and third columns of the first and third rows, (rows [0,2] and columns [1,2]) you'd do what you're doing... (Your description of modifying rows [0,2] and columns [1,2] is exactly the result you get, right?)

提交回复
热议问题