I'm trying to write a function in Python using Numpy that would take as input a vector x = array([x_1, x_2, ..., x_n]) and a positive integer m and return an array of dimension n by m of the form (say n==3, m==4):
array([[ x_1, x_1^2, x_1^3, x_1^4],
[ x_2, x_2^2, x_2^3, x_2^4],
[ x_3, x_3^2, x_3^3, x_3^4]])
So far I have
import numpy as np
def f(x, m):
return x ** np.arange(1, m+1)
which works fine for n==1, but raises an exception for n > 1.
I am trying to avoid using loops. Is there a nice way of making this in Numpy?
Thank you!