hanning python

pdpi pdpinheiro at gmail.com
Wed Sep 9 10:46:49 EDT 2009


On Sep 9, 3:27 am, sturlamolden <sturlamol... at yahoo.no> wrote:
> On 9 Sep, 00:24, Steven D'Aprano
>
> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
> > A decent vendor-supplied implementation will include error checking that
> > you otherwise would need to implement yourself, so yes.
>
> Not for code like this:
>
>
>
> >>> import numpy as np
> >>> n = np.arange(101)
> >>> w = 0.5*(1.0-np.cos(2*np.pi*n/(100.)))

Well, I went and dug into NumPy. They write it as 0.5 - 0.5 * cos
(...), and special case N = 1, and properly error check N < 1. Still,
probably because of differences in dictionary look ups (because of
namespace scopes), np.hanning, on average, takes a wee bit over half
as long as your case, and yours is only a shade faster than

>>> window = [0.5 - math.cos(2 * x * math.pi /100.) for x in range(101)]

(Yes, I know I should've used xrange instead of range)



More information about the Python-list mailing list