The general way to create an array is by using the function array. The syntax to create a real-valued vector would be:
V = array([1., 2., 1.], dtype=float)
To create a complex vector with the same data, you use:
V = array([1., 2., 1.], dtype=complex)
When no type is specified, the type is guessed. The array function chooses the type that allows storing all the specified values:
V = array([1, 2]) # [1, 2] is a list of integers V.dtype # int64 V = array([1., 2]) # [1., 2] mix float/integer V.dtype # float64 V = array([1. + 0j, 2.]) # mix float/complex V.dtype # complex128
NumPy silently casts floats into integers, which might give unexpected results:
a = array([1, 2, 3]) a[0] = 0.5 a # now: array([0, 2, 3])
The same, often unexpected array type casting happens from complex to float.