1

I have a numpy array like this one

# [[0.64809866 1.4297429  1.76778859]
#  [0.98994126 0.60583935 1.07312068]
#  [0.47607127 0.58659789 1.52184562]
#  [0.6905903  0.33424117 1.50113122]
#  [0.66848235 1.5608329  2.02750987]

I'd like to find the min of each row, but knowing by index. Like this

# [[0]
#  [1]
#  [0]
#  [1]
#  [0]]

i used np.min(dist, axis=1).reshape(-1, 1) in order to generate a matrix with the min of results, but no idea how to follow from here.

1 Answer 1

2

Try with argmin

a.argmin(axis=1).reshape(-1,1)
array([[0],
       [1],
       [0],
       [1],
       [0]])
Sign up to request clarification or add additional context in comments.

2 Comments

I think I wasn't clear, sorry. I wanted to find the index which is the min value from X1, X2, X3 (my matrix X) so I can create a new one matrix witch every index of every minium value of every row and then concatenate to the original matrix. Sorry for my english
@Sharki check the update , the you need np.hstack([a,a.argmin(axis=1).reshape(-1,1)])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.