Advertisement
milanmetal

[Python] Numpy 1D Array to 3D array

Aug 8th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. # https://stackoverflow.com/questions/48991077/reshape-1d-array-to-3d-array-numpy
  2.  
  3.  
  4. aa = np.arange(160)
  5. >>> bb = np.reshape(aa, (10, 4, 4))
  6. >>> bb
  7. array([[[  0,   1,   2,   3],
  8.         [  4,   5,   6,   7],
  9.         [  8,   9,  10,  11],
  10.         [ 12,  13,  14,  15]],
  11.  
  12.        [[ 16,  17,  18,  19],
  13.         [ 20,  21,  22,  23],
  14.         [ 24,  25,  26,  27],
  15.         [ 28,  29,  30,  31]],
  16.  
  17.        [[ 32,  33,  34,  35],
  18.         [ 36,  37,  38,  39],
  19.         [ 40,  41,  42,  43],
  20.         [ 44,  45,  46,  47]],
  21.  
  22.        [[ 48,  49,  50,  51],
  23.         [ 52,  53,  54,  55],
  24.         [ 56,  57,  58,  59],
  25.         [ 60,  61,  62,  63]],
  26.  
  27.        [[ 64,  65,  66,  67],
  28.         [ 68,  69,  70,  71],
  29.         [ 72,  73,  74,  75],
  30.         [ 76,  77,  78,  79]],
  31.  
  32.        [[ 80,  81,  82,  83],
  33.         [ 84,  85,  86,  87],
  34.         [ 88,  89,  90,  91],
  35.         [ 92,  93,  94,  95]],
  36.  
  37.        [[ 96,  97,  98,  99],
  38.         [100, 101, 102, 103],
  39.         [104, 105, 106, 107],
  40.         [108, 109, 110, 111]],
  41.  
  42.        [[112, 113, 114, 115],
  43.         [116, 117, 118, 119],
  44.         [120, 121, 122, 123],
  45.         [124, 125, 126, 127]],
  46.  
  47.        [[128, 129, 130, 131],
  48.         [132, 133, 134, 135],
  49.         [136, 137, 138, 139],
  50.         [140, 141, 142, 143]],
  51.  
  52.        [[144, 145, 146, 147],
  53.         [148, 149, 150, 151],
  54.         [152, 153, 154, 155],
  55.         [156, 157, 158, 159]]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement