Given a Numpy array/matrix, what is pythonic way to count the number of complex, pure real and pure imaginary number:
[[ 1. +0.j 1. +0.j 1. +0.j 1. +0.j 1. +0.j ]
[ 1. +0.j 0.309+0.951j -0.809+0.588j -0.809-0.588j 0.309-0.951j]
[ 1. +0.j -0.809+0.588j 0.309-0.951j 0.309+0.951j -0.809-0.588j]
[ 1. +0.j -0.809-0.588j 0.309+0.951j 0.309-0.951j -0.809+0.588j]
[ 1. +0.j 0.309-0.951j -0.809-0.588j -0.809+0.588j 0.309+0.951j]]
Note: Please ignore the fact that complex numbers are superset of Imaginary and Real numbers.
A number is complex if and only if its imaginary part is not zero, and its real part is not zero. Therefore:
Use
numpy.isreal.A number is pure imaginary if and only if:
Therefore: