擅长:python、mysql、java
<p>见<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.atleast_1d.html" rel="noreferrer">atleast_1d</a>:</p>
<blockquote>
<p>Convert inputs to arrays with at least one dimension.</p>
</blockquote>
<pre><code>>>> import numpy as np
>>> x = 42 # x is a scalar
>>> np.atleast_1d(x)
array([42])
>>> x_is_array = np.array(42) # A zero dim array
>>> np.atleast_1d(x_is_array)
array([42])
>>> x_is_another_array = np.array([42]) # A 1d array
>>> np.atleast_1d(x_is_another_array)
array([42])
>>> np.atleast_1d(np.ones((3, 3))) # Any other numpy array
array([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
</code></pre>