Computing an array with a given shape containing powers of x = complex(0, 1)

I am trying to create a 9-lines array (shape = (9,)) containing

powers of x = complex(0, 1): 1, x, x**2, …, x**8.

I do not know if there is someone who knows what is meant by the statement powers of x = complex(0, 1) and how in your opinion this series might be computed.

Thanks

>Solution :

If I understand correctly, you can use:

out = complex(0,1)**np.arange(9)

output:

array([ 1.+0.j,  0.+1.j, -1.+0.j, -0.-1.j,  1.+0.j,  0.+1.j, -1.+0.j,
       -0.-1.j,  1.+0.j])

If by 9 lines you rather mean a shape of (9,1), use instead:

out = complex(0,1)**np.arange(9)[:,None]

output:

array([[ 1.+0.j],
       [ 0.+1.j],
       [-1.+0.j],
       [-0.-1.j],
       [ 1.+0.j],
       [ 0.+1.j],
       [-1.+0.j],
       [-0.-1.j],
       [ 1.+0.j]])

explanation:

np.arange(9) is creating the array array([0, 1, 2, 3, 4, 5, 6, 7, 8]), and vectorization of x**powers is computing x**power for each power of powers

x = complex(0, 1)
# 0 + 1j

powers = np.arange(9)
# array([0, 1, 2, 3, 4, 5, 6, 7, 8])

x**powers
# array([ 1.+0.j,   1
#         0.+1.j,   x
#        -1.+0.j,   x**2
#        -0.-1.j,   x**3
#         1.+0.j,
#         0.+1.j,
#        -1.+0.j,
#        -0.-1.j,
#         1.+0.j,   x**8
#         ])

Leave a Reply