Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How do I take from other dimensions? #740

Open
@mrocklin

Description

@mrocklin

In NumPy I do this:

In [1]: import numpy as np

In [2]: x = np.arange(9).reshape((3, 3))

In [3]: x
Out[3]: 
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [4]: ind = np.array([True, False, True])

In [5]: x[ind, :]
Out[5]: 
array([[0, 1, 2],
       [6, 7, 8]])

In [6]: x[:, ind]
Out[6]: 
array([[0, 2],
       [3, 5],
       [6, 8]])

In DyND-python I can get partway there

In [7]: from dynd import nd

In [8]: x = nd.array(x)

In [9]: x
Out[9]: 
nd.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]],
         type="3 * 3 * int64")

In [10]: ind = nd.array(ind)

In [11]: nd.take(x, ind)
Out[11]: 
nd.array([[0, 1, 2], [6, 7, 8]],
         type="var * 3 * int64")

But don't know how to proceed to take along the other dimension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions