法一
import numpy as np
a = np.arange(start=0, stop=9, step=1, dtype=int)
a.resize(3, 3)
print a
print type(a)
[[0 1 2]
[3 4 5]
[6 7 8]]
<type 'numpy.ndarray'>
Process finished with exit code 0
要特别注意这里的 .resize
没有返回值:
print a.resize(3, 3)
None
Process finished with exit code 0
法二
import numpy as np
a = np.arange(start=0, stop=9, step=1, dtype=int).reshape(3, 3)
print a
print type(a)
[[0 1 2]
[3 4 5]
[6 7 8]]
<type 'numpy.ndarray'>
Process finished with exit code 0