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

前端 未结 4 1461
迷失自我
迷失自我 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 15:51

    one work around: ndarray.flatten, np.put(), ndarray.reshape

    try ndarray.flatten(array), that way you are dealing with a one dim array which can be manipulated with numpy.put(array,[indices],[values]). Then use ndarray.reshape() to get to the original dimensions.

提交回复
热议问题