美文网首页
numpy中的常量

numpy中的常量

作者: meowwzzz | 来源:发表于2018-09-08 11:48 被阅读385次

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

相关文章

  • numpy中的常量

    Constants 正无穷 numpy.inf numpy.Inf numpy.Infinity numpy.in...

  • 2020-10-20Numpy

    数据类型及数组创建 通常将 numpy 库 缩写为 np import numpy as np 1、常量 nump...

  • numpy运算

    numpy的与运算 numpy 中 argsort() numpy 中的布尔索引

  • 学习Tensorflow中遇到的一些小问题

    书中的代码示例自定义tf常量和变量后,返回的结果包含numpy格式的内容,而我在ipython中并没有这些值。需要...

  • NumPy API(十七)——掩码数组操作

    掩码数组操作 常量 ma.MaskType numpy.bool_ 的别名 创造 根据现有数据 ma.masked...

  • pandas numpy

    pandas 时间序列操作 python numpy教程 Numpy中矩阵对象(matrix) numpy中的数据...

  • NumPy中的聚合运算

    在向量上进行聚合运算 Python中的sum() 和 NumPy中的numpy.sum() sum()和numpy...

  • numpy

    numpy.array()中的数据格式必须一致 numpy从txt中读取数据到矩阵中 numpy.genfromt...

  • TensorFlow(2) 基本操作

    创建变量 特殊矩阵和常量 创建随机值 示例程序 保存模型 NumPy数据转换成TensorFlow数据 tf.pl...

  • Pytorch神经网络基础Torch,Numpy,Variabl

    Torch是可以在神经网络中替代numpy。Torch自称为神经网络中的numpy。 Pytorch与Numpy的...

网友评论

      本文标题:numpy中的常量

      本文链接:https://www.haomeiwen.com/subject/lspkgftx.html