Chris@87: """ Chris@87: ========= Chris@87: Constants Chris@87: ========= Chris@87: Chris@87: Numpy includes several constants: Chris@87: Chris@87: %(constant_list)s Chris@87: """ Chris@87: # Chris@87: # Note: the docstring is autogenerated. Chris@87: # Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import textwrap, re Chris@87: Chris@87: # Maintain same format as in numpy.add_newdocs Chris@87: constants = [] Chris@87: def add_newdoc(module, name, doc): Chris@87: constants.append((name, doc)) Chris@87: Chris@87: add_newdoc('numpy', 'Inf', Chris@87: """ Chris@87: IEEE 754 floating point representation of (positive) infinity. Chris@87: Chris@87: Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for Chris@87: `inf`. For more details, see `inf`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: inf Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'Infinity', Chris@87: """ Chris@87: IEEE 754 floating point representation of (positive) infinity. Chris@87: Chris@87: Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for Chris@87: `inf`. For more details, see `inf`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: inf Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'NAN', Chris@87: """ Chris@87: IEEE 754 floating point representation of Not a Number (NaN). Chris@87: Chris@87: `NaN` and `NAN` are equivalent definitions of `nan`. Please use Chris@87: `nan` instead of `NAN`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: nan Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'NINF', Chris@87: """ Chris@87: IEEE 754 floating point representation of negative infinity. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : float Chris@87: A floating point representation of negative infinity. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: isinf : Shows which elements are positive or negative infinity Chris@87: Chris@87: isposinf : Shows which elements are positive infinity Chris@87: Chris@87: isneginf : Shows which elements are negative infinity Chris@87: Chris@87: isnan : Shows which elements are Not a Number Chris@87: Chris@87: isfinite : Shows which elements are finite (not one of Not a Number, Chris@87: positive infinity and negative infinity) Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic Chris@87: (IEEE 754). This means that Not a Number is not equivalent to infinity. Chris@87: Also that positive infinity is not equivalent to negative infinity. But Chris@87: infinity is equivalent to positive infinity. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> np.NINF Chris@87: -inf Chris@87: >>> np.log(0) Chris@87: -inf Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'NZERO', Chris@87: """ Chris@87: IEEE 754 floating point representation of negative zero. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : float Chris@87: A floating point representation of negative zero. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: PZERO : Defines positive zero. Chris@87: Chris@87: isinf : Shows which elements are positive or negative infinity. Chris@87: Chris@87: isposinf : Shows which elements are positive infinity. Chris@87: Chris@87: isneginf : Shows which elements are negative infinity. Chris@87: Chris@87: isnan : Shows which elements are Not a Number. Chris@87: Chris@87: isfinite : Shows which elements are finite - not one of Chris@87: Not a Number, positive infinity and negative infinity. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic Chris@87: (IEEE 754). Negative zero is considered to be a finite number. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> np.NZERO Chris@87: -0.0 Chris@87: >>> np.PZERO Chris@87: 0.0 Chris@87: Chris@87: >>> np.isfinite([np.NZERO]) Chris@87: array([ True], dtype=bool) Chris@87: >>> np.isnan([np.NZERO]) Chris@87: array([False], dtype=bool) Chris@87: >>> np.isinf([np.NZERO]) Chris@87: array([False], dtype=bool) Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'NaN', Chris@87: """ Chris@87: IEEE 754 floating point representation of Not a Number (NaN). Chris@87: Chris@87: `NaN` and `NAN` are equivalent definitions of `nan`. Please use Chris@87: `nan` instead of `NaN`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: nan Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'PINF', Chris@87: """ Chris@87: IEEE 754 floating point representation of (positive) infinity. Chris@87: Chris@87: Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for Chris@87: `inf`. For more details, see `inf`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: inf Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'PZERO', Chris@87: """ Chris@87: IEEE 754 floating point representation of positive zero. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : float Chris@87: A floating point representation of positive zero. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: NZERO : Defines negative zero. Chris@87: Chris@87: isinf : Shows which elements are positive or negative infinity. Chris@87: Chris@87: isposinf : Shows which elements are positive infinity. Chris@87: Chris@87: isneginf : Shows which elements are negative infinity. Chris@87: Chris@87: isnan : Shows which elements are Not a Number. Chris@87: Chris@87: isfinite : Shows which elements are finite - not one of Chris@87: Not a Number, positive infinity and negative infinity. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic Chris@87: (IEEE 754). Positive zero is considered to be a finite number. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> np.PZERO Chris@87: 0.0 Chris@87: >>> np.NZERO Chris@87: -0.0 Chris@87: Chris@87: >>> np.isfinite([np.PZERO]) Chris@87: array([ True], dtype=bool) Chris@87: >>> np.isnan([np.PZERO]) Chris@87: array([False], dtype=bool) Chris@87: >>> np.isinf([np.PZERO]) Chris@87: array([False], dtype=bool) Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'e', Chris@87: """ Chris@87: Euler's constant, base of natural logarithms, Napier's constant. Chris@87: Chris@87: ``e = 2.71828182845904523536028747135266249775724709369995...`` Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: exp : Exponential function Chris@87: log : Natural logarithm Chris@87: Chris@87: References Chris@87: ---------- Chris@87: .. [1] http://en.wikipedia.org/wiki/Napier_constant Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'inf', Chris@87: """ Chris@87: IEEE 754 floating point representation of (positive) infinity. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : float Chris@87: A floating point representation of positive infinity. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: isinf : Shows which elements are positive or negative infinity Chris@87: Chris@87: isposinf : Shows which elements are positive infinity Chris@87: Chris@87: isneginf : Shows which elements are negative infinity Chris@87: Chris@87: isnan : Shows which elements are Not a Number Chris@87: Chris@87: isfinite : Shows which elements are finite (not one of Not a Number, Chris@87: positive infinity and negative infinity) Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic Chris@87: (IEEE 754). This means that Not a Number is not equivalent to infinity. Chris@87: Also that positive infinity is not equivalent to negative infinity. But Chris@87: infinity is equivalent to positive infinity. Chris@87: Chris@87: `Inf`, `Infinity`, `PINF` and `infty` are aliases for `inf`. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> np.inf Chris@87: inf Chris@87: >>> np.array([1]) / 0. Chris@87: array([ Inf]) Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'infty', Chris@87: """ Chris@87: IEEE 754 floating point representation of (positive) infinity. Chris@87: Chris@87: Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for Chris@87: `inf`. For more details, see `inf`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: inf Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'nan', Chris@87: """ Chris@87: IEEE 754 floating point representation of Not a Number (NaN). Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : A floating point representation of Not a Number. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: isnan : Shows which elements are Not a Number. Chris@87: isfinite : Shows which elements are finite (not one of Chris@87: Not a Number, positive infinity and negative infinity) Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic Chris@87: (IEEE 754). This means that Not a Number is not equivalent to infinity. Chris@87: Chris@87: `NaN` and `NAN` are aliases of `nan`. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> np.nan Chris@87: nan Chris@87: >>> np.log(-1) Chris@87: nan Chris@87: >>> np.log([-1, 1, 2]) Chris@87: array([ NaN, 0. , 0.69314718]) Chris@87: Chris@87: """) Chris@87: Chris@87: add_newdoc('numpy', 'newaxis', Chris@87: """ Chris@87: A convenient alias for None, useful for indexing arrays. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: `numpy.doc.indexing` Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> newaxis is None Chris@87: True Chris@87: >>> x = np.arange(3) Chris@87: >>> x Chris@87: array([0, 1, 2]) Chris@87: >>> x[:, newaxis] Chris@87: array([[0], Chris@87: [1], Chris@87: [2]]) Chris@87: >>> x[:, newaxis, newaxis] Chris@87: array([[[0]], Chris@87: [[1]], Chris@87: [[2]]]) Chris@87: >>> x[:, newaxis] * x Chris@87: array([[0, 0, 0], Chris@87: [0, 1, 2], Chris@87: [0, 2, 4]]) Chris@87: Chris@87: Outer product, same as ``outer(x, y)``: Chris@87: Chris@87: >>> y = np.arange(3, 6) Chris@87: >>> x[:, newaxis] * y Chris@87: array([[ 0, 0, 0], Chris@87: [ 3, 4, 5], Chris@87: [ 6, 8, 10]]) Chris@87: Chris@87: ``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``: Chris@87: Chris@87: >>> x[newaxis, :].shape Chris@87: (1, 3) Chris@87: >>> x[newaxis].shape Chris@87: (1, 3) Chris@87: >>> x[None].shape Chris@87: (1, 3) Chris@87: >>> x[:, newaxis].shape Chris@87: (3, 1) Chris@87: Chris@87: """) Chris@87: Chris@87: if __doc__: Chris@87: constants_str = [] Chris@87: constants.sort() Chris@87: for name, doc in constants: Chris@87: s = textwrap.dedent(doc).replace("\n", "\n ") Chris@87: Chris@87: # Replace sections by rubrics Chris@87: lines = s.split("\n") Chris@87: new_lines = [] Chris@87: for line in lines: Chris@87: m = re.match(r'^(\s+)[-=]+\s*$', line) Chris@87: if m and new_lines: Chris@87: prev = textwrap.dedent(new_lines.pop()) Chris@87: new_lines.append('%s.. rubric:: %s' % (m.group(1), prev)) Chris@87: new_lines.append('') Chris@87: else: Chris@87: new_lines.append(line) Chris@87: s = "\n".join(new_lines) Chris@87: Chris@87: # Done. Chris@87: constants_str.append(""".. const:: %s\n %s""" % (name, s)) Chris@87: constants_str = "\n".join(constants_str) Chris@87: Chris@87: __doc__ = __doc__ % dict(constant_list=constants_str) Chris@87: del constants_str, name, doc Chris@87: del line, lines, new_lines, m, s, prev Chris@87: Chris@87: del constants, add_newdoc