Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>arange</code> generates evenly spaced 1D ndarray in range <code>[1,limit+1]</code> in your example. </p> <p>Now say you want an multi-dim ndarray of evenly spaced arrays. Then you may use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html" rel="nofollow"><code>arange</code></a> to generate each component of your 2D ndarray. You convert result of <code>arange</code> to a python list with <code>list()</code>, to make it the right format to be an argument of <code>ndarray</code> constructor.</p> <p>It all depends on your purpose. As you deal with math. analysis, what you look for may be a grid:</p> <pre><code>&gt;&gt;&gt; np.mgrid[0:5,0:5] array([[[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]]) </code></pre> <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.mgrid.html" rel="nofollow">More here.</a></p> <p>EDIT: After you posted the code : as DSM mentions, <code>np.vectorize</code> is a good way to do. <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html" rel="nofollow">From doc</a>,</p> <pre><code>class numpy.vectorize(pyfunc, otypes='', doc=None, excluded=None, cache=False) </code></pre> <blockquote> <p>Generalized function class.</p> <p>Define a vectorized function which takes a nested sequence of objects or numpy arrays as inputs and returns a numpy array as output. The vectorized function evaluates pyfunc over successive tuples of the input arrays like the python map function, except it uses the broadcasting rules of numpy.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload