We've already seen a very useful attribute of arrays, the shape attribute. There are three more, flat, real and imaginary.
Accessing the flat attribute of an array returns the flattened, or ravel() 'ed version of that array, without having to do a function call. The returner array has the same number of elements as the input array, but is of rank-1. One cannot set the flat attribute of an array, but one can use the indexing and slicing notations to modify the contents of the array:
These attributes exist only for complex arrays. They return respectively arrays filled with the real and imaginary parts of their elements. .imag is a synonym for .imaginary . The arrays returned are not contiguous (except for arrays of length 1, which are always contiguous.). .real , .imag and .imaginary are modifiable:
[ 0. +1.j 0.84147098+0.54030231j 0.90929743-0.41614684j]
[ 0. +0.j 0.84147098+1.j 0.90929743+2.j]
>>> x = reshape(arange(10), (2,5)) + 0j # make complex array
[[ 0.+0.j 1.+0.j 2.+0.j 3.+0.j 4.+0.j]
[ 5.+0.j 6.+0.j 7.+0.j 8.+0.j 9.+0.j]]
>>> print x.typecode(), x.real.typecode()