In [2]:
import numpy as np
In [54]:
a = np.arange(10)
a
Out[54]:
In [33]:
type(a)
Out[33]:
In [80]:
a.dtype
Out[80]:
In [81]:
a.shape
Out[81]:
In [38]:
a = np.arange(10.0)
a
Out[38]:
In [111]:
a.dtype
Out[111]:
In [115]:
a = array(["1","2","3"])
a
Out[115]:
In [116]:
a = array(["1","2","3",1,2,3])
a
Out[116]:
In [44]:
a = np.arange(1,10)
a
Out[44]:
In [48]:
a = np.arange(1,10,2)
a
Out[48]:
In [50]:
a = np.arange(10,1,-1)
a
Out[50]:
In [53]:
print('a[0] = %s, a[1] = %s') % (a[0],a[1])
In [11]:
b = array([1,2,3,4,5])
In [13]:
type(b)
Out[13]:
In [15]:
b ** 2
Out[15]:
In [16]:
b + 1
Out[16]:
In [18]:
a + b
In [117]:
a1 = array([1,2,3,4,5])
a2 = array([5,4,3,2,1])
a1 + a2
Out[117]:
In [128]:
a1_a2 = concatenate((a1,a2))
Out[128]:
In [103]:
m = array([arange(1,4),arange(4,7)])
m
Out[103]:
In [105]:
m.shape
Out[105]:
In [107]:
print(m[0,0])
print(m[0,1])
print(m[1,0])
print(m[1,1])
In [171]:
m = array([arange(1,5),arange(4,7)])
m
Out[171]:
In [172]:
m.shape
Out[172]:
In [173]:
m[0]
Out[173]:
In [131]:
In [145]:
a1 = array([[1,2],[3,4]])
a2 = array([5,6])
print(a1)
print(a2)
In [147]:
concatenate((a1,a2),axis=0)
In [152]:
print(a1.shape)
print(a2.shape)
In [161]:
a1 = array([[1,2],[3,4]])
a2 = array([[5,6]])
print(a1)
print(a2)
In [164]:
print(a1.shape)
print(a2.shape)
In [166]:
concatenate((a1,a2),axis=0)
Out[166]:
In [1]:
concatenate((a1,a2.T),axis = 1)
In [4]:
a = np.arange(24)
In [5]:
a
Out[5]:
In [7]:
b = a.reshape(2,3,4)
In [9]:
b
Out[9]:
In [11]:
b[0,0,0]
Out[11]:
In [13]:
b[:,0,0]
Out[13]:
In [15]:
b[0,:,:]
Out[15]:
In [16]:
b[0,...]
Out[16]:
In [22]:
b[0,1,::2]
Out[22]:
In [24]:
b[0]+b[1]
Out[24]:
In [42]:
b[0] * b[1]
Out[42]:
In [53]:
np.arange(3*2).reshape(3,2).dot(np.arange(3*2).reshape(3,2).T)
Out[53]:
In [29]:
#計算一二維矩陣每個欄的總和, 平均數, 標準差
In [33]:
a = np.arange(10).reshape(2,5)
In [35]:
a
Out[35]:
In [41]:
a[:,1].sum()
Out[41]: