Up Numpy 作成: 2021-05-06
更新: 2021-05-06


  • Pythonでの数値計算を高速化
    • 大量のデータ処理をする時の速度を上げたい時は,Pythonのリストではなく NumPyの配列 (ndarray) を使用

  • ndarray 配列
    • 1次元 (ベクトル) : numpy.array
      2次元 (行列) : numpy.matrix
      3次元以上 (「テンソル」)


      $ python >>> import numpy as np >>> a = np.matrix([[0,1,2],[3,4,5]]) >>> b = np.matrix([[0,1],[2,3],[4,5]]) >>> c = np.matmul(a,b) >>> a [[0 1 2] [3 4 5]] >>> b [[0 1] [2 3] [4 5]] >>> c [[10 13] [28 40]] >>> a = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]) >>> a_2_3_4 = a.reshape([2,3,4]) >>> a_2_3_4 array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]) >>> a_2_2_2_3 = a.reshape([2,2,2,3]) >>> a_2_2_2_3 array([[[[ 0, 1, 2], [ 3, 4, 5]], [[ 6, 7, 8], [ 9, 10, 11]]], [[[12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23]]]])>>>