[Numpy-discussion] Creating a sine wave with exponential decay

Hameer Abbasi einstein.edison at gmail.com
Tue Jul 23 11:37:01 EDT 2019


Hi Ram,

No, NumPy doesn’t have a way. And it newer versions, it probably won’t create two arrays if all the dtypes match, it’ll do some magic to re use the existing ones, although it will use multiple loops instead of just one.

You might want to look into NumExpr or Numba if you want an efficient implementation.

Get Outlook for iOS<https://aka.ms/o0ukef>

________________________________
From: NumPy-Discussion <numpy-discussion-bounces+einstein.edison=gmail.com at python.org> on behalf of Ram Rachum <ram at rachum.com>
Sent: Tuesday, July 23, 2019 7:29 pm
To: numpy-discussion at python.org
Subject: [Numpy-discussion] Creating a sine wave with exponential decay


Hi everyone! Total Numpy newbie here.

I'd like to create an array with a million numbers, that has a sine wave with exponential decay on the amplitude.

In other words, I want the value of each cell n to be sin(n) * 2 ** (-n * factor).

What would be the most efficient way to do that?

Someone suggested I do something like this:

y = np.sin(x) * np.exp(newfactor * x)

But this would create 2 arrays, wouldn't it? Isn't that wasteful? Does Numpy provide an efficient way of doing that without creating a redundant array?


Thanks for your help,

Ram Rachum.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190723/dc546277/attachment-0001.html>


More information about the NumPy-Discussion mailing list