>

LoeiJe

:D 获取中...

何以解忧?唯有暴富

numpy学习笔记

numpy学习笔记

三角函数

sin(x)
cos(x)
tan(x)
sinh(x)
conh(x)
tanh(x)
arccos(x)
arctan(x)
arcsin(x)
arccosh(x)
arctanh(x)
arcsinh(x)
arctan2(x,y)

arctan2(x,y) 返回 arctan(x/y)

向量操作

dot(x,y)
inner(x,y)
cross(x,y)
vdot(x,y)
outer(x,y)
kron(x,y)
tensordot(x,y[,axis])

其他操作

exp(x)
log(x)
log10(x)
sqrt(x)
absolute(x)
conjugate(x)
negative(x)
ceil(x)
floor(x)
fabs(x)
hypot(x)
fmod(x)
maximum(x,y)
minimum(x,y)

hypot 返回对应点 (x,y) 到原点的距离。

类型处理

iscomplexobj
iscomplex
isrealobj
isreal
imag
real
real_if_close
isscalar
isneginf
isposinf
isinf
isfinite
isnan
nan_to_num
common_type
typename

修改形状

atleast_1d
atleast_2d
atleast_3d
expand_dims
apply_over_axes
apply_along_axis
hstack
vstack
dstack
column_stack
hsplit
vsplit
dsplit
split
squeeze

其他有用函数

fix
mod
amax
amin
ptp
sum
cumsum
prod
cumprod
diff
angle

unwrap
sort_complex
trim_zeros
fliplr
flipud
rot90
diag
eye
select
extract
insert

roots
poly
any
all
disp
unique
nansum
nanmax
nanargmax
nanargmin
nanmin

nan 开头的函数会进行相应的操作,但是忽略 nan 值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 2019-10-25 不更新时间了
# numpy 学习笔记
# icenaive
# 参考: https://github.com/lijin-THU/notes-python
# 仅供个人学习使用
#
# 13. 一般函数

import numpy as np

x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
# 返回对应点到原点的距离
print(np.hypot(x, y))

# 正无穷
print(np.inf)

# 负无穷
print(-np.inf)
# 非法值
print(np.nan)
print("非法值\n")
print(np.array([0]) / 0.0) #不报错 返回一个非法值
# 只有 0/0 会得到 nan,非0值除以0会得到无穷:
a = np.arange(5.0)
b = a / 0.0
print(a, b)

# 检查是否为无穷
print(np.isinf(1.0))
print(np.isinf(np.inf))

# nan与任何数比较都False
print(b == np.nan)

# 想要找出nan需要使用isnan
print(np.isnan(b))