Skip to content

Instantly share code, notes, and snippets.

@rayepeng
Created May 19, 2021 01:22
Show Gist options
  • Save rayepeng/84bee9cdda754f291f3948f24fd6c167 to your computer and use it in GitHub Desktop.
Save rayepeng/84bee9cdda754f291f3948f24fd6c167 to your computer and use it in GitHub Desktop.
numpy reshape用法 #Python
In [1]: import numpy as np
In [2]: arr = np.array([1,2,3,4,5,6])
In [3]: arr = arr.reshape(2,1,3)
In [4]: arr
Out[4]:
array([[[1, 2, 3]],
[[4, 5, 6]]])
In [5]: brr = np.array([1,2,3,4,5,6,7,8,9,10,11,12])
In [6]: brr = brr.reshape(2,2,3)
In [7]: brr
Out[7]:
array([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 7, 8, 9],
[10, 11, 12]]])
In [8]: crr = np.array([1,2,3])
In [9]: crr =crr.reshape(1,1,3)
In [10]: crr
Out[10]: array([[[1, 2, 3]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment