Elementwise indexing of a vector by a multidimentional array
2 次查看(过去 30 天)
显示 更早的评论
I have:
- A, an n-dimentional array of integers, whose values are in the range 1-100,
- and T, a 1-dimentional, length 100 array of values.
I want a new n-dimentional array B which, for each corresponding (same position) integer c of A, has the value T(c).
What is the proper way to do this without a for loop, preferrably that works on a gpuArray?
0 个评论
回答(2 个)
DGM
2022-1-18
I have no idea what's ideal for gpuArray, but this is how it would be done with linear indexing.
T = 11:20; % a vector
A = randi([1 10],2,2,2) % a 3D array
B = T(A) % linear indexing
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!