開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
行列プログラマー(Philip N. Klein (著)、 松田 晃一 (翻訳)、 弓林 司 (翻訳)、 脇本 佑紀 (翻訳)、 中田 洋 (翻訳)、 齋藤 大吾 (翻訳)、オライリージャパン)の1章(体)、1.4(C(複素数)と遊ぼう)、1.4.5(複素数に i を掛けること: 90度の回転)の問題1.4.7を取り組んでみる。
課題 1.4.8
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from plotting import plot
s = {2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j}
plot({z * 1j * 1/2 for z in s})
input()
入出力結果(Terminal, IPython)
$ ./sample4_8.py q $
課題 1.4.9
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from plotting import plot
s = {2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j}
plot({z * 1j * 1/2 + (2-1j) for z in s})
input()
入出力結果(Terminal, IPython)
$ ./sample4_9.py q $
課題 1.4.10
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from plotting import plot
import image
filename = 'img01.png'
data = image.file2image(filename)
height = len(data)
width = len(data[0])
pts = [ x + (height - y) * 1j
for y, l in enumerate(data)
for x, (pt, _, _) in enumerate(l)
if pt < 120]
plot({pt for pt in pts}, max(width, height))
input()
入出力結果(Terminal, IPython)
$ ./sample4_10.py q $
課題 1.4.11
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from plotting import plot
import image
s = {2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j}
def f(z):
reals = {z0.real for z0 in z}
imags = {z0.imag for z0 in z}
real_c = (max(reals) + min(reals)) / 2
imag_c = (max(imags) + min(imags)) / 2
return {z0 - real_c - imag_c * 1j for z0 in z}
plot(f(s))
input()
入出力結果(Terminal, IPython)
$ ./sample4_11.py q $
課題 1.4.12
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from plotting import plot
import image
filename = 'img01.png'
data = image.file2image(filename)
height = len(data)
width = len(data[0])
pts = [ x + (height - y) * 1j
for y, l in enumerate(data)
for x, (pt, _, _) in enumerate(l)
if pt < 120]
def f(z):
reals = {z0.real for z0 in z}
imags = {z0.imag for z0 in z}
real_c = (max(reals) + min(reals)) / 2
imag_c = (max(imags) + min(imags)) / 2
return {z0 - real_c - imag_c * 1j for z0 in z}
plot(f(pts), max(width, height))
input()
入出力結果(Terminal, IPython)
$ ./sample4_12.py q $
0 コメント:
コメントを投稿