擅长:python、mysql、java
<p><code>ndim</code>告诉您数组的维数,如:</p>
<pre><code>def f(x):
if np.ndim(x) == 1:
return g(x)
elif np.ndim(x) == 2:
return np.array([g(xi) for xi in x])
else:
# Whatever you want to do with more than 2 directions
return None
</code></pre>