[Linear Algebra](python) Numpy

berry ·2021년 8월 1일
0

Linear Algebra

목록 보기
1/5
post-thumbnail

🧩 Numpy

import numpy as np

📌 Sum

a1 = np.array(5)
a2 = np.array(3)
a3 = a1 + a2
>>> 8
  1. (Scalar)
s = np.array(5)
x = s+3
>>> 8

📌 Vector

v = np.array([1,2,3])
x = v[0]

print(v)
print(x)
print(v[1:])

>>> [1 2 3]
     1
    [2 3]

📌 Matrices

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

print(m)
print(m[1][2])

>>>[[1 2 3]
    [4 5 6]
    [7 8 9]]
    6

📌 Tensor

t = np.array([[[[1],[3]],[[2],[4]],[[5],[6]]],
[[[7],[8]],[[9],[10]],[[11],[12]]],
[[[13],[14]],[[15],[16]],[[17],[18]]]])

print(t.shape)

>>>(3, 3, 2, 1) 

📎 Example

1. **Python's way**

values = [1,2,3,4,5]

values = [values[i]+5 for i in range(len((values)))]
print(values[0],'end')
print(range(len(values)))
print(values)

>>> 6 end
    range(0, 5)
    [6, 7, 8, 9, 10]


2. **Numpy's way **

values = [1,2,3,4,5]
values = np.array(values) + 5

>>>[ 6  7  8  9 10]

profile
Engineer

0개의 댓글