Sorry to bump my own issue, but I wonder if just no-one knows, or if it has been overlooked, or maybe I did not explain my questions right? Should I rather ask this on SO? Or should I just be more patient...?

Thanks!
Vincent.

On 1/13/22 11:43, Vincent Schut wrote:
Hi,

I'm having a hard(ish) time adding the right type annotations to some numpy-using code. I hope someone more knowledgeable can give me some advise.

Specifically, the following questions pop up:

- How do I correctly type a ndarray as being an array of float64, such that mypy can infer that when I index this array, the result is actually a float (currently I consistently get "Any" after indexing)?

- How can I get compatibility between np.floating and builtin.float? Currently, some numpy functions are typed to return np.floating[Any] (e.g. np.linalg.norm). When I feed this result into something that is supposed to receive a builtin.float, mypy complains. Is an explicit cast(float, <the np.floating[Any] thing>) the prefered way to gain compatibility here?

versions:
numpy: 1.22.0
python: 3.8.10 (unfortunately we're limited to this version)
mypy: 0.931

Thanks!
Vincent.

--

        

Vincent Schut

Remote Sensing Software Engineer

+31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands

Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com>
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to