LoginSignup
1
1

More than 5 years have passed since last update.

松尾研のDeep Learning基礎講座演習コンテンツをやってみた(Chap.2-総合)

Last updated at Posted at 2018-05-30

個人的に、何かをするとき、説明書を読んでる時間というのが一番の苦痛です。chap2はそんな章だったような気もします。しかし、なんとかそこを歩き抜けました。 
 さぁ、こっからはやっと実際的なことができるはずです!
オレはようやくのぼりはじめたばかりだからな このはてしなく遠いデータサイエンス坂をよ…

で、今回は解答だけなので折りたたまないよ。
汚解答ではあるけどいわゆるネタバレなので気を付けてね。

総合問題

#(1)
import math

random.seed(0)
#生成
x=np.random.uniform(0.0,1.0,10000)
y=np.random.uniform(0.0,1.0,10000)
#(2)
#math.hypotでの判別
in_circle_index=[i for i in range(0,len(x)) if math.hypot(x[i],y[i])<1]
out_circle_index=[i for i in range(0,len(y)) if math.hypot(x[i],y[i])>=1]
#indexからx,yをとる
in_circle_x=[x[in_circle_index]]
in_circle_y=[y[in_circle_index]]

out_circle_x=[x[out_circle_index]]
out_circle_y=[y[out_circle_index]]
#視覚化
plt.plot(in_circle_x,in_circle_y,'o',color='Blue')
plt.plot(out_circle_x,out_circle_y,'x',color='Cyan')
xlim=(0,1)
ylim=(0,1)
plt.legend
#数えるのは配列の長さでいい
in_point_number=len(in_circle_index)
print('Number:{}',format(in_point_number))
out_point_number=len(out_circle_index)


松尾研のDeep Learning基礎講座演習コンテンツをやってみた(chap2-総合).png

#(3)
#点の数の比もin:all=π/4:1になるはず。比をとって4倍してみよう
print('π={}',format(4*in_point_number/len(x)))

以上!また会おう!!!

1
1
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
1