python 2 D配列および図面


1.2 D配列の値
注意:2 D配列であれ、1 D配列であれ、配列内のデータ型はそっくりです.すなわち、数値型であれば、すべて数値型です.
#    
import numpy as np

list1=[[1.73,1.68,1.71,1.89,1.78],
      [54.4,59.2,63.6,88.4,68.7]]
list3=[1.73,1.68,1.71,1.89,1.78]
list4=[54.4,59.2,63.6,88.4,68.7]
list5=np.array([1.73,1.68,1.71,1.89,1.78])
list6=np.array([54.4,59.2,63.6,88.4,68.7])
#      
list=np.array([[1.73,1.68,1.71,1.89,1.78],
      [54.4,59.2,63.6,88.4,68.7]])
print type(list1)
#  list          ,     list3        list4        ,    nump  array  
# print list3/list4
#       list5/list6
print list5/list6
print type(list)  #  :
print list.shape  #  :(2, 5)   5     
print list[0][2]  #  :1.71 ,  0      ,    1.71
print list[0,2]   #  :1.71 ,  0      ,    1.71
print list[:,1:3] #  :[[  1.68   1.71] [ 59.2   63.6 ]],     ,         
print list[1,:]   #  :[ 54.4  59.2  63.6  88.4  68.7],         

2.絵を描く
(1)線図
import matplotlib.pyplot as plt
year=[1950,1970,1990,2010]
pop=[2.518,3.68,5.23,6.97]
# 1.  
#  plt。plot   ,          
plt.plot(year,pop)
# python  show     
plt.show()
 (2)   
 
  
import matplotlib.pyplot as plt
year=[1950,1970,1990,2010]
pop=[2.518,3.68,5.23,6.97]
#2.   ,    scat       
plt.scatter(year,pop)
plt.show()
(3)ヒストグラム
import matplotlib.pyplot as plt
#3.   
#  hist(x,bins=10)    ,   x  List,        ,bins           bin        
values=[0,0.6,1.4,1.6,2.2,2.5,2.6,3.2,3.5,3.9,4.2,6]
# 12   ,bins=3    3 , (0,2),(2,4),(4,6),         (2,4)      
plt.hist(values,bins=3)
plt.show()