[SciPy-user] Create n-dim array from axis
Paul Hilscher
p.hilscher at lsw.uni-heidelberg.de
Wed Mar 25 04:12:27 EDT 2009
> def create_array2(nodes):
> # nodes is a list with lists of axis points (e.g. [[2, 3, 5, 10],
> [0, 1], [100, 200, 500, 1000]]
> shape = tuple([len(a) for a in nodes])
> idx = numpy.indices(shape)
> result = numpy.zeros(idx.shape, numpy.float)
> for d in range(idx.shape[0]):
> result[d] = numpy.take(nodes[d], idx[d])
> return result.transpose()
>
> create_array2([[0.0, 0.5, 1], [2.0, 2.5, 3]])
>
Thanks a lot, it work perfectly fine for me.
If this feature is also useful for others, is there any chance to
have it included in numpy ?
Paul
More information about the SciPy-User
mailing list