0

I am trying to add only to the right side of the array indx but I want to keep the left side of the array. How would I be able to get the Expected Output.

Code:

import numpy as np

number = 3
indx=np.array([[    0,     1],
 [    1,   765],
 [    0,  4355],
 [    1,  9364],
 [    0, 12110],
 [    1, 15233],
 [    0, 16246],
 [    1, 18889]])
indx = indx[:,1] + number

Output:

[    4   768  4358  9367 12113 15236 16249 18892]

Expected Output

[[    0     4]
 [    1   768]
 [    0  4358]
 [    1  9367]
 [    0 12113]
 [    1 15236]
 [    0 16249]
 [    1 18892]]
1
  • indx[:,1] += number or make sure you only assign to the column indx[:,1] = indx[:,1] + number Commented Aug 25, 2021 at 22:58

1 Answer 1

1
import numpy as np
 indx=np.array(
 [[    0,     1], 
 [    0,  4355],
 [    1,  9364],
 [    0, 12110],
 [    1, 15233],
 [    0, 16246],
 [    1, 18889]])
indx[:,1] = indx[:,1] + 3
print(indx)
[[    0     4]
 [    1   768]
 [    0  4358]
 [    1  9367]
 [    0 12113]
 [    1 15236]
 [    0 16249]
 [    1 18892]]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.