<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div>
<div>
<div>
<div style="direction: ltr;">Hi Ram,</div>
<div><br>
</div>
<div style="direction: ltr;">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.</div>
<div><br>
</div>
<div style="direction: ltr;">You might want to look into NumExpr or Numba if you want an efficient implementation.</div>
</div>
<div><br>
</div>
<div class="ms-outlook-ios-signature">Get <a href="https://aka.ms/o0ukef">Outlook for iOS</a></div>
</div>
<div> </div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="dir="ltr""><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> NumPy-Discussion <numpy-discussion-bounces+einstein.edison=gmail.com@python.org> on behalf of Ram Rachum <ram@rachum.com><br>
<b>Sent:</b> Tuesday, July 23, 2019 7:29 pm<br>
<b>To:</b> numpy-discussion@python.org<br>
<b>Subject:</b> [Numpy-discussion] Creating a sine wave with exponential decay
<div> </div>
</font></div>
<meta content="text/html; charset=utf-8">
<div dir="ltr">
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
Hi everyone! Total <span class="gmail-il">Numpy</span> newbie here.</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
I'd like to create an array with a million numbers, that has a sine wave with exponential decay on the amplitude.</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
In other words, I want the value of each cell <code style="margin:0px; padding:1px 5px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; vertical-align:baseline; box-sizing:inherit; background-color:rgb(239,240,241); white-space:pre-wrap">n</code> to
be <code style="margin:0px; padding:1px 5px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; vertical-align:baseline; box-sizing:inherit; background-color:rgb(239,240,241); white-space:pre-wrap">sin(n)
* 2 ** (-n * factor)</code>.</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
What would be the most efficient way to do that?</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
Someone suggested I do something like this: </p>
<pre class="gmail-m_3550683175654527263gmail-lang-py gmail-m_3550683175654527263gmail-prettyprint gmail-m_3550683175654527263gmail-prettyprinted" style="white-space:pre-wrap; margin-top:0px; margin-bottom:1em; padding:12px 8px; border:0px; font-variant-numeric:inherit; font-variant-east-asian:inherit; font-stretch:inherit; line-height:inherit; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; vertical-align:baseline; box-sizing:inherit; width:auto; max-height:600px; overflow:auto; background-color:rgb(239,240,241); border-radius:3px; color:rgb(57,51,24)"><code style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; vertical-align:baseline; box-sizing:inherit; white-space:inherit"><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">y </span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">=</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)"> np</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">.</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">sin</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">(</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">x</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">)</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)"> </span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">*</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)"> np</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">.</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">exp</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">(</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">newfactor </span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">*</span><span class="gmail-m_3550683175654527263gmail-pln" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)"> x</span><span class="gmail-m_3550683175654527263gmail-pun" style="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; font-stretch:inherit; line-height:inherit; font-family:inherit; vertical-align:baseline; box-sizing:inherit; color:rgb(48,51,54)">)</span></code></pre>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
But this would create 2 arrays, wouldn't it? Isn't that wasteful? Does <span class="gmail-il">Numpy</span> provide an efficient way of doing that without creating a redundant array?</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
<br>
</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
Thanks for your help,</p>
<p style="color:rgb(36,39,41); font-family:inherit; font-size:15px; font-style:inherit; font-variant:inherit; font-weight:inherit; margin:0px 0px 1em; padding:0px; border:0px; font-stretch:inherit; line-height:inherit; vertical-align:baseline; box-sizing:inherit; clear:both">
Ram Rachum.</p>
</div>
</div>
</body>
</html>