First row of numpy.ones is still populated after referencing another matrix

前端 未结 5 969
说谎
说谎 2021-01-26 10:01

I have a matrix \'A\' whose values are shown below. After creating a matrix \'B\' of ones using numpy.ones and assigning the values from \'A\' to \'B\' by indexing \'i\' rows an

5条回答
  •  故里飘歌
    2021-01-26 10:42

    Python starts counting at 0, so your code should work find if you replace np.arange(1,9) with np.arange(9)

    In [11]: np.arange(1,9)
    Out[11]: array([1, 2, 3, 4, 5, 6, 7, 8])
    
    In [12]: np.arange(9)
    Out[12]: array([0, 1, 2, 3, 4, 5, 6, 7, 8])
    

提交回复
热议问题