[Numpy-discussion] ndarray typing advise

2022-01-13 Thread Vincent Schut

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 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 ~
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


[Numpy-discussion] np.convolve question

2022-01-13 Thread cae
Hello,

I am a mechanical engineer and am using Numpy Convolve to smoothen 1D data 
collected from physical testing for a diesel engine. (I found convolve the best 
after comparing with other smoothing methodologies)
I tried reading the numpy manual and the wikipedia article referenced in it.
But I would specifically like to ask/discuss what would happen if the second 1D 
input is not given? what type of window will the function pass the data through 
to smoothen it?

Here are the articles I have read to implement my smoothing code:
References:
1. https://numpy.org/doc/stable/reference/generated/numpy.convolve.html
2. https://en.wikipedia.org/wiki/Convolution
3. 
https://stackoverflow.com/questions/20618804/how-to-smooth-a-curve-in-the-right-way
 

NOTE: Apologies if I have unknowingly broken any rule of this forum - I can 
delete the thread if it doesn't meet any set guidelines of the forum.

Best,
Pushkar Sheth
Bangalore, India.
___
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


[Numpy-discussion] Re: np.convolve question

2022-01-13 Thread Robert Kern
On Thu, Jan 13, 2022 at 10:47 AM  wrote:

> Hello,
>
> I am a mechanical engineer and am using Numpy Convolve to smoothen 1D data
> collected from physical testing for a diesel engine. (I found convolve the
> best after comparing with other smoothing methodologies)
> I tried reading the numpy manual and the wikipedia article referenced in
> it.
> But I would specifically like to ask/discuss what would happen if the
> second 1D input is not given?


The second input is required, which is evident from the docstring and could
be ascertained by just trying it. Are you instead asking rather if
np.convolve() could be modified to not have to take the second argument?

If so, no, I don't think we would. There are no sensible defaults.
Convolution is inherently a very general operation that combines two inputs
to achieve a variety of effects, not just smoothing.

what type of window will the function pass the data through to smoothen it?


There are several ways to build a low-pass (i.e. smoothing) filter. My
favorite first choice is the Savitzky-Golay filter as mentioned several
times in the StackOverflow answers that you link to. It constructs a
low-pass filter window (i.e. the second 1D input) according to some simple,
understandable design rules and then uses convolution. I recommend starting
with `scipy.signal.savgol_filter()`. If you need to reuse the same filter
window for lots of signals, you can use `scipy.signal.savgol_coeffs()` to
get that window first, and then use `np.convolve()` explicitly.

Here are the articles I have read to implement my smoothing code:
> References:
> 1. https://numpy.org/doc/stable/reference/generated/numpy.convolve.html
> 2. https://en.wikipedia.org/wiki/Convolution
> 3.
> https://stackoverflow.com/questions/20618804/how-to-smooth-a-curve-in-the-right-way


-- 
Robert Kern
___
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


[Numpy-discussion] MacPython travis funds have run out (again)

2022-01-13 Thread Charles R Harris
Hi All,

Travis wheel build problems again. There is still a positive balance, but
apparently it is insufficiently positive. Which is strange if ARM64 is
free. Wheel builds have been failing since last weekend.

Matti, could you ask for more credits? I'm thinking we really need to move
off travis for ARM builds.

Chuck
___
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


[Numpy-discussion] Re: MacPython travis funds have run out (again)

2022-01-13 Thread Charles R Harris
On Thu, Jan 13, 2022 at 6:04 PM Charles R Harris 
wrote:

> Hi All,
>
> Travis wheel build problems again. There is still a positive balance, but
> apparently it is insufficiently positive. Which is strange if ARM64 is
> free. Wheel builds have been failing since last weekend.
>
> Matti, could you ask for more credits? I'm thinking we really need to move
> off travis for ARM builds.
>
> Chuck
>

Note that we have ~95,000 credits, but that is insufficient. I suspect some
weird business rule, maybe because we overran credits last time we ran out
of money.

Chuck
___
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


[Numpy-discussion] Re: np.convolve question

2022-01-13 Thread Pushkar Sheth
I understand. I see that the span variable is undergoing some operation and 
being used as a window in the stackoverflow article (the function - 
smooth_data_convolve_my_average).

To understand the working - I will have to build some plots to visualise how 
the function (smooth_data_convolve_my_average) is working. (This is beyond the 
scope of this forum - will have to do it myself)

Thanks for your comment Robert Kern!

Best,
Pushkar
___
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