Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

how to take specific data from 3 dims NDArray? #19217

Answered by szha
dooothink asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, I think what you need is gather_nd

x = nd.array([
    ...:     [
    ...:         [1,2,3,4],
    ...:         [5,6,7,8],
    ...:         [9,10,11,12]
    ...:     ],
    ...:     [
    ...:         [13,14,15,16],
    ...:         [17,18,19,20],
    ...:         [21,22,23,24]
    ...:     ]
    ...: ])
    ...: idx = nd.array([[0, 1], [0, 2]])
    ...: y = nd.gather_nd(x, idx)
    ...: print(y)
    ...:

[[ 1.  2.  3.  4.]
 [21. 22. 23. 24.]]
<NDArray 2x4 @cpu(0)>

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dooothink
Comment options

Answer selected by szha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #19217 on September 25, 2020 00:04.