I wanna make a function of a multi-dimensional array from one-dimensional index array with any dimension. For example, I have
x=np.array([1,2,3])
def extend_array(x,d)
If I put d=2, then the resulting array is
[[1,1],
[1,2],
[1,3],
[2,1],
[2,2],
[2,3],
[3,1],
[3,2],
[3,3]]
or input can be (n,d) instead of (x,d) so that n refers
np.array(range(1,n+1))
I think there is a function for this, but I cannot find one. Would you please help me with this problem?
from itertools import product
t=list(product(x,repeat=d))
This will gives the desired result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.