I have a numpy.ndarray like this:
array([[ 11.18033989, 0. ],
[ 8.24621125, 3. ],
[ 13.03840481, 5. ],
[ 6. , 5.38516481],
[ 11.18033989, 3.16227766],
[ 0. , 11.18033989],
[ 8.06225775, 4.24264069]])
I want to get a new array A, such that A[i] is the index of minimum element in ith row of above matrix. Such as this: array([1, 1, 1, 1, 1, 0, 1])
I can do it with for loops with argmin, but since I want this algorithm to be scalable, I am looking for a way to do it using a vectorized implementation. I guess numpy would offer such a feature, but I am new to numpy, so I am not sure where to look.
If X
is your array,
X.argmin(axis=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With