Help us understand the problem. What is going on with this article?

簡単に試せるNumpyでの線形計算コード➁(初級編)

More than 1 year has passed since last update.

「簡単に試せるNumpyでの線形計算コード➀(初級編)」
(Numpyの概要と行列の表示のさせ方と、行列の足し算に関して)
https://qiita.com/kenfukaya/items/fae288827976a8f79dc7

実際に線形計算をしてみた

・Numpyのインポート

```import numpy as np
```

・形状の変更(6列→2行×3列)

```a = np.array([1,2,3,4,5,6])
b = a.reshape(2,3)

print('a =' , a)
print('b =' , b)
```

```a = [1 2 3 4 5 6]
b = [[1 2 3]
[4 5 6]]
```

となり、a(6列)→b(2行×3列)に変更されていることを確認

・形状を確認

```b = ([[1,2,3],[4,5,6]])
b.shape
```

```(2,3)
```

2行×3列の形状を確認

・要素数を確認

```b = ([[1,2,3],[4,5,6]])
b.size
```

```6
```

・要素ごとの算術演算

```c = np.array([[3,7,4],[2,8,5],[8,5,1]])
d = np.array([[2,7,4],[4,9,4],[9,1,5]])

print('c =', c)

print('d =' ,d)

print('c+d =', c+d) #要素ごとの足し算

print('c-d =' , c-d ) #要素ごとの引き算

print('c*d =', c*d)   #要素ごとの掛け算

print('c/d =', c/d)  #要素ごとの割り算
```

```c = [[3 7 4]
[2 8 5]
[8 5 1]]

d = [[2 7 4]
[4 9 4]
[9 1 5]]

c+d = [[ 5 14  8]
[ 6 17  9]
[17  6  6]]

c-d = [[ 1  0  0]
[-2 -1  1]
[-1  4 -4]]

c*d = [[ 6 49 16]
[ 8 72 20]
[72  5  5]]

c/d = [[1.5        1.         1.        ]
[0.5        0.88888889 1.25      ]
[0.88888889 5.         0.2       ]]
```

・要素が全て0の行列を出力(ここでは3行×4列)

```x = np.zeros((3,4))
print('x = ', x)
```

```x =  [[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
```

・要素が全て1の行列を出力(ここでは2行×3列)

```y = np.ones((2,3))
print('y =',y)
```

```y = [[1. 1. 1.]
[1. 1. 1.]]
```
Why do not you register as a user and use Qiita more conveniently?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away