Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy minimum like np.outer()

Maybe I'm just being lazy here, but let's say that I have two arrays, of length n and m, and I'd like a pairwise minimum of all of the elements of the two arrays compared against each other. For example:

a = [1,5,3]
b = [2,4]
cross_min(a,b)
= [[1,1],[2,4],[2,3]]

This is similar to the behavior of np.outer(), except that instead of multiplying the two arrays, it computes the minimum of the two elements.

Is there an operation in numpy that does a similar thing?

I know that I can just run np.minimum() along b and stack the results together. I'm wondering if this is a well-known operation that I just don't know the name of.

like image 626
Jamie Cho Avatar asked Apr 23 '26 04:04

Jamie Cho


1 Answers

You can use np.minimum.outer(a, b)

like image 182
Eric Avatar answered Apr 25 '26 16:04

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!