LoginSignup
1
0

More than 3 years have passed since last update.

scalar, vector, matrices の次元の違い

Last updated at Posted at 2019-08-25
import numpy as np
#この中からarray,shape,ndim関数を使う

scalarの次元は0(0次元のテンソル)であることを確認

#scalar
#numpyの中にあるarray関数
s = np.array(3)
s.shape
# =>()
s.ndim
# =>0
x = s + 5
x
# =>8

vectorの次元は1(1次元のテンソル)であることを確認

#vector

v = np.array([2,3,4])
v.shape
# =>(3,) 
#columunが3つあって一次元。タプルで返される。

v.ndim
# =>1

v[1:]
#numpy特有の表現。訓練用とテスト用に分ける時よく使う。
# =>array([3, 4])
#2番目以降全て

matricesの次元は2(2次元のテンソル)であることを確認

#metrices

m = np.array([[1,2,3],[4,5,6],[7,8,9]])
m.shape
# =>(3, 3)

m.ndim
# =>2

m
# =>array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

m[1]
# =>array([4, 5, 6])
#2番目の要素にアクセス

m[1][1]
# =>5

参考: NumPy・Python3で】ゼロから作るニューラルネットワーク(バックプロップを徹底マスター) (https://www.udemy.com/neuralnet/)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0