||
python学习
math 模块
精确除 :’/’ :3/2=1.5
地板除:’//’ : 3//2=1
取模操作:’%’:4%2=1
math.modf(-1.24)
==> (-02.4, -1)
math.modf(1.56)
==>(0.56,1.0)
math.modf
商和余数
度分秒转换为十进制度
dem =[1,2,3]
deg=dms[0]+dms[1]/60.0+dms[2]/3600.0
deg
1.034166666667
度分秒 ==> 十进制度
抽象为函数
def dms2deg(dms): deg=dms[0]+dms[1]/60.0+dms[2]/3600.0 return deg dms2deg(dms)
十进制度转换为度分秒
a=np.array([1,1,1])b=np.array([2,2,2])c=np.vstack((a,b))#上下合并
np.newaxis,: 在行增加一个维度
:,np.newaxis 在列增加一个维度
np.hstack() #纵向合并
np.concatenate() 上下 左右合并 axis 在那个维度 进行合并
np.split()
a[1] [1]第一行第一列
a[2,1] 第二行第一列
a[:,1]第一列所有数
for row in A.T:
a.flat 变相迭代
np.sin() np.cos()
np.tan() np.cot()
a=np.array([1,1] [4,5])b=np.arange(4).reshape(2,2)c=np.dot(a,b) #矩阵的乘法
np.random.random(2,4) 随机生成2行4列的随机数据
np.max() 最大值
np.min() 最小值
np.sum() 求和
np.sum(a,axis=0)行中求和 axis =1在每一列进行求和
np.argmin() 最小值的索引
np.argmax()最大值的索引
np.mean() np.average() 平均值的计算
np.median() 中位数的求解
np.cumsum() 累加求和 逐步加
np.nozero() 非零的数
np.sort() 排序
np.transpose() 矩阵的反向
np.clip() 截取
numpy.array([1,2,3]
[3,4,5]) #将列表转换为矩阵
array.ndim 维度 2
array.shape 形状 (2,3)
array.size 大小 6
import numpy as np a=np.array([1,3] [3,4],dtype=np.int64)print(a)
a=np.ones((2,3)) 生成 2行3列都为1的矩阵
a=np.zero((3,4),dtpye=np.int32)生成3行4列都为0的矩阵
a=np.empty((3,4))生成3行4列都为接近0的矩阵
a=np.arange(10,20)生成排序从10到20的矩阵
a=np.arange(12).reshape(3,4)生成0-20的数据为3行4列
a=np.arange(4)b=np.array([3,4,5,6])print(a,b)c=b-aprint(c)
deg=1.03416666666667sec=deg*3600.0sec_part=sec.modf(sec)sec_dec=sec_part[0]sec_int=sec_part[1]s=sec_int%60mins=sec_int//60m=mins %60d=mins//60
函数化
def deg2dms(deg):#deg=1.03416666666667 sec=deg*3600.0 sec_part=sec.modf(sec) sec_dec=sec_part[0] sec_int=sec_part[1] s=sec_int%60 mins=sec_int//60 m=mins %60 d=mins//60 return dms
度==> 度分秒
numpy
三角函数
numpy 的索引
numpy的合并
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-20 01:51
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社