简体   繁体   中英

how to make an array of D-dimensional coordinates from D arrays in numpy

In numpy, I have D arrays each of length n, and I would like to produce a length n array of D-dimensional coordinates from those arrays. Each array, then, provides the values for one axis of the coordinates.

For example, in 2 dimensions:

import numpy as np
x = np.arange(5)
y = x + 4

#from which I would like to make this nd.array:
[[0, 4],
 [1, 5],
 [2, 6],
 [3, 7],
 [4, 8]]

You can do this with column_stack :

>>> np.column_stack((x, y))
array([[0, 4],
       [1, 5],
       [2, 6],
       [3, 7],
       [4, 8]])

column_stack takes a sequence of arrays, so if you have D arrays you want to stack, you can call column_stack with D directly.

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