티스토리 뷰

python

Coding the Matrix-3장 Vector

zedo 2016. 5. 15. 17:51

Charpter3. Vector

In [8]:
import math
s=[3.14159, 2.718281828, -1.0, 2.0]
e=list(enumerate(s))
print(e)
[(0, 3.14159), (1, 2.718281828), (2, -1.0), (3, 2.0)]
In [11]:
list(zip([1,2,3,4], [1,2,3,4]))
Out[11]:
[(1, 1), (2, 2), (3, 3), (4, 4)]
In [14]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
limit=4
s=[2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j]
for x in range(len(s)) :
    plt.plot(s[x].real, s[x].imag, 'ro-', label='complex')
    ##  plt.plot([0,s[x].real], [0, s[x].imag])
plt.xlim(-limit,limit)
plt.ylim(-limit,limit)
plt.ylabel('Imaginary')
plt.xlabel('Real')  
plt.grid(True)
plt.show()
In [16]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
limit=4
soa = np.array([0,0,3,1.5])
X,Y,U,V = zip(soa)
ax = plt.gca()
ax.quiver(X,Y,U,V,  angles='xy', scale_units='xy', scale=1)
ax.set_xlim([-5,5])
ax.set_ylim([-5,5])
plt.draw()
plt.grid(True)
plt.show()
In [18]:
u=[1,1,1,1,1]
v=[10,20,0,40,-100]
sum(u*v for (u,v) in list(zip(u,v)))
Out[18]:
-30

'python' 카테고리의 다른 글

A byte of python 공부한 내용 요약  (0) 2016.05.22
Coding the Matrix -3장 Vector(추가)  (0) 2016.05.15
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함