You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

当从数组降维为矩阵时,base::drop()是否应保留维度名称?

关于base::drop()移除维度名称的疑问

我发现当数组的维度没有设置元素特定名称时,base::drop()会直接移除整个数组的维度名称。以下是复现代码:

a = array(
  data = 1:12,
  dim = c(2,3,4),
  dimnames = list("test" = NULL, "test2" = NULL, "test3" = NULL))
a[1,,,drop = FALSE] |> dimnames()
#> $test
#> NULL
#> 
#> $test2
#> NULL
#> 
#> $test3
#> NULL
a[1,,,drop = TRUE] |> dimnames() # 我认为这等同于`a[1,,,drop = FALSE] |> drop()`
#> NULL

我原本期望执行a[1,,,drop = FALSE] |> drop()后,返回结果的维度名称应该是这样的:

#> $test2
#> NULL
#> 
#> $test3
#> NULL

请问这是drop()函数的预期行为吗?


内容的提问来源于stack exchange,提问作者Doug Ezra Morrison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:22:33