Can I use np.arange with lists as my inputs?
<p>The relevant excerpt of my code is as follows:</p>

<pre><code>import numpy as np

def create_function(duration, start, stop):
    rates = np.linspace(start, stop, duration*1000)
    return rates

def generate_spikes(duration, start, stop):
    rates = [create_function(duration, start, stop)]
    array = [np.arange(0, (duration*1000), 1)]
    start_value = [np.repeat(start, duration*1000)]
    double_array = [np.add(array,array)]
    times = np.arange(np.add(start_value,array), np.add(start_value,double_array), rates)
    return times/1000.
</code></pre>

<p>I know this is really inefficient coding (especially the start_value and double_array stuff), but it's all a product of trying to somehow use <code>arange</code> with lists as my inputs.</p>

<p>I keep getting this error:</p>

<pre><code>Type Error: int() argument must be a string, a bytes-like element, or a number, not 'list'
</code></pre>

<p>Essentially, an example of what I'm trying to do is this:</p>

<p>I had two arrays <code>a = [1, 2, 3, 4]</code> and <code>b = [0.1, 0.2, 0.3, 0.4]</code>, I'd want to use <code>np.arange</code> to generate <code>[1.1, 1.2, 1.3, 2.2, 2.4, 2.6, 3.3, 3.6, 3.9, 4.4, 4.8, 5.2]</code>? (I'd be using a different step size for every element in the array.)</p>

<p>Is this even possible? And if so, would I have to flatten my list?</p>

<p>You can use <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>broadcasting</code></a> there for efficiency purposes -</p>

<pre><code>(a + (b[:,None] * a)).ravel('F')
</code></pre>

<p>Sample run -</p>

<pre><code>In [52]: a
Out[52]: array([1, 2, 3, 4])

In [53]: b
Out[53]: array([ 0.1,  0.2,  0.3,  0.4])

In [54]: (a + (b[:,None] * a)).ravel('F')
Out[54]: 
array([ 1.1,  1.2,  1.3,  1.4,  2.2,  2.4,  2.6,  2.8,  3.3,  3.6,  3.9,
        4.2,  4.4,  4.8,  5.2,  5.6])
</code></pre>

<p>Looking at the expected output, it seems you are using just the first three elements off <code>b</code> for the computation. So, to achieve that target, we just slice the first three elements and do that computation, like so -</p>

<pre><code>In [55]: (a + (b[:3,None] * a)).ravel('F')
Out[55]: 
array([ 1.1,  1.2,  1.3,  2.2,  2.4,  2.6,  3.3,  3.6,  3.9,  4.4,  4.8,
        5.2])
</code></pre>

python python-3.x numpy