numpy基础简介
numpy介紹【了解】
?個(gè)開源的Python科學(xué)計(jì)算庫(kù)
計(jì)算起來要?python簡(jiǎn)潔?效
Numpy使?ndarray對(duì)象來處理多維數(shù)組
?NumPy提供了?個(gè)N維數(shù)組類型ndarray,它描述了相同類型的“items”的 集合。 ?成numpy對(duì)象:np.array() ndarray的優(yōu)勢(shì)【掌握】
內(nèi)存塊?格
- list -- 分離式存儲(chǔ),存儲(chǔ)內(nèi)容多樣化
- ndarray -- ?體式存儲(chǔ),存儲(chǔ)類型必須?樣
ndarray?持并?化運(yùn)算(向量化運(yùn)算)?
ndarray底層是?C語?寫的,效率更?,釋放了GIL
初識(shí)
import numpy as np score = np.array( [[80, 89, 86, 67, 79], [78, 97, 89, 67, 81], [90, 94, 78, 67, 74], [91, 91, 90, 67, 69], [76, 87, 75, 67, 86], [70, 79, 84, 67, 84], [94, 92, 93, 67, 64], [86, 85, 83, 67, 80]] ) score?ndarray和原生Python效率對(duì)比
import random import time import numpy as np a = [] for i in range(100000000):a.append(random.random())# 通過%time魔法方法, 查看當(dāng)前行的代碼運(yùn)行一次所花費(fèi)的時(shí)間 %time sum1=sum(a)b=np.array(a)%time sum2=np.sum(b)ndarray的使用
數(shù)組的屬性
score.shape #數(shù)組形狀 score.ndim #數(shù)組維數(shù) score.size #數(shù)組元素的個(gè)數(shù) score.itemsize #?個(gè)數(shù)組元素的?度(字節(jié)) score.dtype #數(shù)組元素的類型總結(jié)
- 上一篇: Oracle函数——字符函数
- 下一篇: 第一周礼拜五 神借着祂的众仆人行事(下)