“Numpy”的版本间差异

来自Shiyin's note
跳到导航 跳到搜索
第18行: 第18行:
*roll #平移
*roll #平移
*array[::-1] 数组倒序
*array[::-1] 数组倒序

===格式输出===
x = np.random.random(10)
np.set_printoptions(precision=3, suppress=True):
print(x)
*另外一个方法
def ndprint(a, format_string ='{0:.2f}'):
print [format_string.format(v,i) for i,v in enumerate(a)]


==vectorize==
==vectorize==

2017年11月9日 (四) 08:23的版本

http://bigsec.net/b52/scipydoc/numpy_intro.html

ndarray

  • shape() #数组的形状,虽然len()可以运行
  • size() #数组的总元素
  • a=np,empty_like(b) #初始化一个和b数组一样shape的空数组
  • 产生序列数组 a=np.arange(20)
  • 合并两个数组 np.append(array1,array2)
  • 选择数组在某个范围之内 sel=np.where((wave < 6800) & (wave > 3800))
  • asarray
  • astype
  • clip(a,a_min,a_max)
array(a).clip(a_min.a_max)
  • reduce,reduceat
reduceat 有点复杂 参见[1]
  • unique
  • sort
  • roll #平移
  • array[::-1] 数组倒序

格式输出

x = np.random.random(10)
np.set_printoptions(precision=3, suppress=True):
print(x)
  • 另外一个方法
def ndprint(a, format_string ='{0:.2f}'):
   print [format_string.format(v,i) for i,v in enumerate(a)]

vectorize

  • 可以将只能对数值计算的函数,变成可以对数组计算,比如积分
import scipy.integrate as integrate
  
    vec_expint=np.vectorize(expint) 
def expint(t1,t2):
    return integrate.quad(CSFH,t1,t2)[0]

随机数

  • random.rand(20,20)