首页 > 代码库 > Python学习笔记(十三)ndarray

Python学习笔记(十三)ndarray

技术分享

技术分享

 

技术分享

aArray = array([(1,2,3), (4,5,6)])sin(aArray)bArray = aArray.reshape(3, 2)# 行求和 ()aArray.sum(axis = 0)# array([ 5, 7, 9 ])# 列求和aArray.sum(axis = 1)# array([ 6, 15 ])
cArray = array([1, 3, 5])cArray[:1]dArray = array([2, 4, 6])eArray = array([7, 8, 9])where(cArray > 2, dArray, eArray)# array([7, 4, 6]); cArray第一个值不大于2, 取eArray:7# cArray第二值大于二,取dArray:4; cArray第三个值大于2, 取dArray:6
def fun(x, y):return (x+1) * (y+1)# (9, 9)是序列大小,从0开始arr = fromfunction(fun, (9,9))

技术分享

 

Python学习笔记(十三)ndarray