numpy中的常量

Constants

正无穷

  • numpy.inf
  • numpy.Inf
  • numpy.Infinity
  • numpy.infty
  • numpy.PINF

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

  • y : float
    A floating point representation of positive infinity.

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])

负无穷

  • numpy.NINF

IEEE 754 floating point representation of negative infinity.

Returns

  • y : float
    A floating point representation of negative infinity.

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

正零

  • numpy.PZERO

IEEE 754 floating point representation of positive zero.

Returns

  • y : float
    A floating point representation of positive zero.

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])

负零

  • numpy.NZERO

IEEE 754 floating point representation of negative zero.

Returns

  • y : float
    A floating point representation of negative zero.

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])

非数值

  • numpy.NAN
  • numpy.NaN
  • numpy.nan

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

  • numpy.e

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

e = 2.71828182845904523536028747135266249775724709369995...

伽马

  • numpy.euler_gamma

γ = 0.5772156649015328606065120900824024310421...

π

  • numpy.pi

pi = 3.1415926535897932384626433...

None的别名

  • numpy.newaxis

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]]] 
'''
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容