如何编写嵌套numpy类型提示

问题描述 投票:0回答:1

我写的 numpy 类型提示没有按我的预期工作。

我有一个

ndarray

 [
 [ 894.45481226  279.40789779  989.63422511  296.75358057]
 [1546.42116975   57.95559617  754.60849398  482.2156838 ]
 [1615.88569942  497.95665529 1642.07014504  253.87915567]
 [ 218.7096641  1212.50328182 1117.34125593  904.91145497]
 ]

我尝试写出像

numpy.typing.NDArray[numpy.typing.NDArray[numpy.float64]]
这样的提示,但皮兰斯告诉我

Could not specialize type "NDArray[ScalarType@NDArray]"
  Type "NDArray[float64]" cannot be assigned to type "generic"
    "NDArray[float64]" is incompatible with "generic"

我不确定是否有办法使其正确。

python numpy python-typing
1个回答
0
投票

这是一个形状为 [4, 4] 的

numpy.typing.NDArray[numpy.float64]
。它的形状描述了嵌套。我不相信您可以在没有第三方工具的情况下对类型中的形状进行编码

© www.soinside.com 2019 - 2024. All rights reserved.