Convert a NumPy array to a Python list with the tolist()
function:
In: b Out: array([ 1.+1.j, 3.+2.j]) In: b.tolist() Out: [(1+1j), (3+2j)]
astype()
function converts the array to an array of the specified type:In: b Out: array([ 1.+1.j, 3.+2.j]) In: b.astype(int) /usr/local/bin/ipython:1: ComplexWarning: Casting complex values to real discards the imaginary part #!/usr/bin/python Out: array([1, 3])
In: b.astype('complex') Out: array([ 1.+1.j, 3.+2.j])
It won't show any warning this time because we used the proper data type.