简体   繁体   中英

Python Numpy Linspace function for bidimensional array

I know it is possible to create numpy arrays using the Linspace function. For example, given a range [x,y] I can make a vector of z elements equally distanced in [x,y]

v = np.linspace(x, y, z, retstep=True)

What if one needs more dimensions? Is it possible to use the same function to generate a 3x4 array? I tried by creating simple arrays and then merge them, but I don't think that is an efficient way to do that

You can use arrays for start and stop point of linspace:

x=np.linspace((0,0,0), (3,5,14), 4, axis=1)
print(x)

This will give the output:

[[ 0.          1.          2.          3.        ]
 [ 0.          1.66666667  3.33333333  5.        ]
 [ 0.          4.66666667  9.33333333 14.        ]]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM