numpy errors #1206
Unanswered
dineshbvadhia
asked this question in
Q&A
numpy errors
#1206
Replies: 4 comments 1 reply
|
Can you provide an actual fully self-contained example? |
0 replies
|
Sure: |
0 replies
This explains a lot. The error is correct in this case, what you'd want here is to either call the |
0 replies
|
If the array type is known (eg. int, float) then use np.ndarray as the annotation instead of npt.ArrayLike - is that correct? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The mypy.ini file includes:
plugins = numpy.typing.mypy_pluginOn python+numpy code, mypy throws errors of the form:
error: Incompatible types in assignment (expression has type "Union[Any, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]", variable has type "int")For example, the line:
indices: np.ndarray = this_vector.nonzero()[0]causes the above error. If changed to a list:
indices: list[float] = this_vector.nonzero()[0].tolist()it works but defeats the purpose of using numpy which performers faster and the code is cleaner.
Please explain what is going on. Thanks
All reactions