add a number to all odd or even indexed elements in numpy array without loops

前端 未结 4 1228
后悔当初
后悔当初 2021-02-07 14:30

Lets say your numpy array is:

 A =    [1,1,2,3,4]

You can simply do:

A + .1

to add a number to tha

4条回答
  •  天涯浪人
    2021-02-07 14:54

    In addition to previous answers, to modify numbers with odd indices you should use A[1::2] instead of A[::2]

提交回复
热议问题