开发者

Python: Setting an element of a Numpy matrix

开发者 https://www.devze.com 2022-12-20 00:14 出处:网络
I am a pretty new to python. I have created an empty matrix a = numpy.zeros(shape=(n,n)) Now I can access each element using

I am a pretty new to python. I have created an empty matrix

a = numpy.zeros(shape=(n,n))

Now I can access each element using

a.item(i,j)

Ho开发者_如何学JAVAw do I set an index (i,j)?


Here's how:

a[i,j] = x


Or

a.itemset((i,j),x)


Try this

a[i,j]=5
0

精彩评论

暂无评论...
验证码 换一张
取 消