logical indexing for dlarrays

4 次查看(过去 30 天)
Rasmus Joussen
Rasmus Joussen 2022-1-17
Hello,
I noticed that when I perform logical indexing on a formatted dlarray, it looses its format. Does anyone has an idea why this is and how I could workaround this? I want to do automatic differentiation afterwards, so I guess when the format is removed, that might be not possible.
Any help would be appreciated!
x = dlarray([1, 2, 3], "CB")
x =
1(C) × 3(B) dlarray 1 2 3
index = [true, false, true];
xNew = x(index)
xNew =
1×2 dlarray 1 3

回答(1 个)

Prince Kumar
Prince Kumar 2022-1-20
编辑:Prince Kumar 2022-1-20
Hi,
This is the intended behaviour once you index "dlarray".
Possible workaround is to re-apply the format. Here is the way to do it :
x = dlarray([1, 2, 3, 4, 5], "CB");
index = [true, false, true];
xNew = x(index);
xNew = dlarray(xNew, "CB")
xNew =
1(C) × 2(B) dlarray 1 3
dims(xNew)
ans = 'CB'
As you can see now, xNew will have the format as "CB".
Hope this helps.
  1 个评论
Rasmus Joussen
Rasmus Joussen 2022-1-20
I just noticed that this was mor a problem of my wrong indexing, since a CB dlarray hast two dimensions I must have to indices:
x = dlarray([1, 2, 3], "CB")
x =
1(C) × 3(B) dlarray 1 2 3
index = [true, false, true];
xNew = x(:, index)
xNew =
1(C) × 2(B) dlarray 1 3
Thank you anyway!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by