PyCharm中具有nptyping和数组的Numpy Typehint [英] Numpy Typehint with nptyping and Array in PyCharm
问题描述
我尝试将numpy与nptyping
的Array
一起使用来进行类型提示.
I try to use numpy with nptyping
's Array
to do my typehinting.
我尝试了以下操作:
enemy_hand: Array[float, 48] = np.zeros(48)
我遇到了打字错误:
预期类型为'Array [float,Any]',而改为'ndarray'
Expected Type 'Array[float, Any]', got 'ndarray' instead
据我了解,
: https://pypi.org/project/nptyping/那就是它的外观.
as far as I understand from this: https://pypi.org/project/nptyping/ thats how it should look.
推荐答案
nptyping
当前无法用于静态分析.图书馆的开发人员在其问题跟踪器上引用了帖子,>
nptyping
is currently useless for static analysis. Quoting a post by the library's developer on its issue tracker,
mypy
尚不支持
mypy
我对那个还没有"寄予太大希望. NumPy的dtype和形状处理很难适应typing
/mypy
静态类型模型,并且nptyping
自己的设计决策不适合NumPy本身.例如,它看起来像开发人员从未考虑过的不是2D数组,因此Array[str, 3]
表示具有3行和未指定列的2D数组,而不是3元素的1D数组.所有的实现方式也都是基于行和列.
I wouldn't put much hope in that "yet". NumPy's dtype and shape handling is very hard to fit into the typing
/mypy
static type model, and nptyping
's own design decisions are a poor fit for NumPy itself. For example, it doesn't look like the dev ever considered arrays that aren't 2D, so Array[str, 3]
represents a 2D array with 3 rows and unspecified columns instead of a 3-element 1D array. All the implementation is in terms of rows and columns, too.
据我所知,nptyping
唯一真正的功能是isinstance
检查,甚至是越野车.
As far as I can tell, the only real functionality nptyping
has is isinstance
checks, and even that's buggy.
这篇关于PyCharm中具有nptyping和数组的Numpy Typehint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!