Issue
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]]
Solution
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]]
Answered By - Mohamed Afify
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.