Lesson 10.1: 宣告與如何使用 array



LESSON 10.1: 產生一維數據陣列
LESSON 10.2: 產生固定間隔的一維數據陣列
LESSON 10.3: 將python 的List轉成numpy array形式
LESSON 10.4: 串接數據陣列
Lesson 10.5: 刪除或新增元素到陣列內


Lesson 10.1: 產生一維數據陣列

import numpy as np
npRange1 = np.arange(1, 10)
print('npRange1=')
print(npRange1);
Note and Comments
np.arange(m, n) 產生數列內容爲m到n-1的數列
	
result



Lesson 10.2: 產生固定間隔的一維數據陣列

Example Code
npRange2 = np.arange(1, 5, 0.5)
print('npRange2=')
print(npRange2);
print('npRange1[0] = '+str(npRange1[0])+', npRange1[2] = '+str(npRange1[2]));
print('npRange1[0:5] = '+str(npRange1[2:5]));
print('npRange1[2:5] = '+str(npRange1[2:5]));
	
Note and Comments
np.arange(m, n, l) 產生m到n-1的每個間隔為l的矩陣 
	








Lesson 10.3: 將python 的List轉成numpy array形式

Example Code 1
import numpy as np;
List1=[1,2,3,4,5,6,7,8,9,10]
npList=np.array(List1)
print("List1="+str(List1))
print("npList="+str(npList))
	

Note and Comments
我們可以利用numpy的array功能來將list轉換成ndarray(numpy 的矩陣型態)
	



Lesson 10.4: 串接數據陣列

Example Code 1
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
c= np.concatenate((a, b), axis=0)
print(c)

d=np.concatenate((a, b.T), axis=1)
print(d)

e=np.concatenate((a, b), axis=None)
print(e)
	

Note and Comments
result
[[1 2]
[3 4]
[5 6]]

[3 4 6]]

[1 2 3 4 5 6]

Lesson 10.5: 刪除或新增元素到陣列內

Example Code
Note and Comments