# [Numpy-discussion] Question about numpy.max(<complex matrix>)

Stuart Brorson sdb@cloud9....
Fri Sep 21 13:49:23 CDT 2007

```Hi guys,

As a NumPy newbie, I am still learning things about NumPy which I didn't
expect.  Today I learned that for a matrix of complex numbers,
numpy.max() returns the element with the largest *real* part, not the
element with the largest *magnitude*.

Is this the desired behavior?

Here's an example:

------------------  <session log>  -----------------
>>> a = numpy.array([ [1+1j, 1+2j], [2+1j, 1.9+1.9j] ])
>>> a
array([[ 1. +1.j ,  1. +2.j ],
[ 2. +1.j ,  1.9+1.9j]])
>>> numpy.max(a)
(2+1j)
>>> math.sqrt(2**2 + 1**2)
2.2360679774997898
>>> math.sqrt(1.9**2 + 1.9**2)
2.6870057685088806
------------------  </session log>  -----------------

FWIW, Matlab does this:

---------------------  <matlab>  -------------------
>> a = [ 1+1*i, 1+2*i; 2+1*i, 1.9+1.9*i ]

a =

1.0000 + 1.0000i   1.0000 + 2.0000i
2.0000 + 1.0000i   1.9000 + 1.9000i

>> max(a)

ans =

2.0000 + 1.0000i   1.9000 + 1.9000i

>> max(max(a))

ans =

1.9000 + 1.9000i
-------------------  </matlab>  ------------------

Do I misunderstand what NumPy is supposed to return?  Should NumPy
even necessarily do the same thing as Matlab?  Or does this resemble
a bug?

Cheers,

Stuart
```