[Numpy-discussion] matrix operation

Ernest Adrogué eadrogue at gmx.net
Wed Mar 17 14:53:48 EDT 2010


17/03/10 @ 11:47 (-0700), thus spake gerardob:
> 
> Let A and B be two n x n matrices.
> 
> I would like to have another n x n  matrix C such that
> C_ij = min {A_ij, B_ij}
> 
> Example:
> A = numpy.array([[2,3],[10,12]])
> B = numpy.array([[1,4],[9,13]])
> 
> Output 
> 
> C = [[1,3],[9,12]]
> 
> The function min(axis) of numpy seems to be only unary.

Try numpy.minimum:

In [7]: np.minimum(A, B)
Out[7]: 
array([[ 1,  3],
       [ 9, 12]])


> Thanks.
> 
> -- 
> View this message in context: http://old.nabble.com/matrix-operation-tp27936387p27936387.html
> Sent from the Numpy-discussion mailing list archive at Nabble.com.
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list