numpy中的常量

2018-09-08  本文已影响385人  meowwzzz

Constants

正无穷

IEEE 754 floating point representation of (positive) infinity.

Use inf because Inf, Infinity, PINF and infty are aliases for inf. For more details, see inf.

Returns

Notes
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Also that positive infinity is not equivalent to negative infinity. But infinity is equivalent to positive infinity.

Examples

>>> np.inf
inf
>>> np.array([1]) / 0.
array([ Inf])

负无穷

IEEE 754 floating point representation of negative infinity.

Returns

Notes
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Also that positive infinity is not equivalent to negative infinity. But infinity is equivalent to positive infinity.

Examples

>>> np.NINF
-inf
>>> np.log(0)
-inf

正零

IEEE 754 floating point representation of positive zero.

Returns

Notes
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). Positive zero is considered to be a finite number.

Examples

>>> np.PZERO
0.0
>>> np.NZERO
-0.0
>>>
>>> np.isfinite([np.PZERO])
array([ True])
>>> np.isnan([np.PZERO])
array([False])
>>> np.isinf([np.PZERO])
array([False])

负零

IEEE 754 floating point representation of negative zero.

Returns

Notes
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). Negative zero is considered to be a finite number.

Examples

>>> np.NZERO
-0.0
>>> np.PZERO
0.0
>>>
>>> np.isfinite([np.NZERO])
array([ True])
>>> np.isnan([np.NZERO])
array([False])
>>> np.isinf([np.NZERO])
array([False])

非数值

IEEE 754 floating point representation of Not a Number (NaN).

NaN and NAN are equivalent definitions of nan. Please use nan instead of NAN.

Returns
y : A floating point representation of Not a Number.

Notes

NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity.

Examples

>>>
>>> np.nan
nan
>>> np.log(-1)
nan
>>> np.log([-1, 1, 2])
array([        NaN,  0.        ,  0.69314718])

自然常数e

Euler’s constant, base of natural logarithms, Napier’s constant.

e = 2.71828182845904523536028747135266249775724709369995...

伽马

γ = 0.5772156649015328606065120900824024310421...

π

pi = 3.1415926535897932384626433...

None的别名

A convenient alias for None, useful for indexing arrays.

Examples

import numpy as np
x=np.array([[2,3,5],[5,6,7]],np.int32)
print(x,"\n\n")
print(x[np.newaxis,:,:],"\n\n")
print(x[:,np.newaxis,:],"\n\n")
print(x[:,:,np.newaxis],"\n\n")

'''
# 原始的x,形状为(2,3)。
[[2 3 5]
 [5 6 7]] 
# 在原先的第一维前面添加了一维,形状变成了(1,2,3)。
[[[2 3 5]
  [5 6 7]]] 
# 在原先第二维前面添加了一维,形状变成了(2,1,3)。
[[[2 3 5]]
 [[5 6 7]]] 
# 添加第三维,形状变成(2,3,1)
[[[2]
  [3]
  [5]]
 [[5]
  [6]
  [7]]] 
'''
上一篇下一篇

猜你喜欢

热点阅读