|
| 1 | +.. currentmodule:: numpy |
| 2 | + |
1 | 3 | *********
|
2 | 4 | Constants
|
3 | 5 | *********
|
4 | 6 |
|
5 |
| -.. automodule:: numpy.doc.constants |
| 7 | +NumPy includes several constants: |
| 8 | + |
| 9 | +.. data:: e |
| 10 | + |
| 11 | + Euler's constant, base of natural logarithms, Napier's constant. |
| 12 | + |
| 13 | + ``e = 2.71828182845904523536028747135266249775724709369995...`` |
| 14 | + |
| 15 | + .. rubric:: See Also |
| 16 | + |
| 17 | + exp : Exponential function |
| 18 | + log : Natural logarithm |
| 19 | + |
| 20 | + .. rubric:: References |
| 21 | + |
| 22 | + https://en.wikipedia.org/wiki/E_%28mathematical_constant%29 |
| 23 | + |
| 24 | + |
| 25 | +.. data:: euler_gamma |
| 26 | + |
| 27 | + ``γ = 0.5772156649015328606065120900824024310421...`` |
| 28 | + |
| 29 | + .. rubric:: References |
| 30 | + |
| 31 | + https://en.wikipedia.org/wiki/Euler-Mascheroni_constant |
| 32 | + |
| 33 | + |
| 34 | +.. data:: inf |
| 35 | + |
| 36 | + IEEE 754 floating point representation of (positive) infinity. |
| 37 | + |
| 38 | + .. rubric:: Returns |
| 39 | + |
| 40 | + y : float |
| 41 | + A floating point representation of positive infinity. |
| 42 | + |
| 43 | + .. rubric:: See Also |
| 44 | + |
| 45 | + isinf : Shows which elements are positive or negative infinity |
| 46 | + |
| 47 | + isposinf : Shows which elements are positive infinity |
| 48 | + |
| 49 | + isneginf : Shows which elements are negative infinity |
| 50 | + |
| 51 | + isnan : Shows which elements are Not a Number |
| 52 | + |
| 53 | + isfinite : Shows which elements are finite (not one of Not a Number, |
| 54 | + positive infinity and negative infinity) |
| 55 | + |
| 56 | + .. rubric:: Notes |
| 57 | + |
| 58 | + NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic |
| 59 | + (IEEE 754). This means that Not a Number is not equivalent to infinity. |
| 60 | + Also that positive infinity is not equivalent to negative infinity. But |
| 61 | + infinity is equivalent to positive infinity. |
| 62 | + |
| 63 | + .. rubric:: Examples |
| 64 | + |
| 65 | + >>> np.inf |
| 66 | + inf |
| 67 | + >>> np.array([1]) / 0. |
| 68 | + array([inf]) |
| 69 | + |
| 70 | + |
| 71 | +.. data:: nan |
| 72 | + |
| 73 | + IEEE 754 floating point representation of Not a Number (NaN). |
| 74 | + |
| 75 | + .. rubric:: Returns |
| 76 | + |
| 77 | + y : A floating point representation of Not a Number. |
| 78 | + |
| 79 | + .. rubric:: See Also |
| 80 | + |
| 81 | + isnan : Shows which elements are Not a Number. |
| 82 | + |
| 83 | + isfinite : Shows which elements are finite (not one of |
| 84 | + Not a Number, positive infinity and negative infinity) |
| 85 | + |
| 86 | + .. rubric:: Notes |
| 87 | + |
| 88 | + NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic |
| 89 | + (IEEE 754). This means that Not a Number is not equivalent to infinity. |
| 90 | + |
| 91 | + `NaN` and `NAN` are aliases of `nan`. |
| 92 | + |
| 93 | + .. rubric:: Examples |
| 94 | + |
| 95 | + >>> np.nan |
| 96 | + nan |
| 97 | + >>> np.log(-1) |
| 98 | + np.float64(nan) |
| 99 | + >>> np.log([-1, 1, 2]) |
| 100 | + array([ nan, 0. , 0.69314718]) |
| 101 | + |
| 102 | + |
| 103 | +.. data:: newaxis |
| 104 | + |
| 105 | + A convenient alias for None, useful for indexing arrays. |
| 106 | + |
| 107 | + .. rubric:: Examples |
| 108 | + |
| 109 | + >>> np.newaxis is None |
| 110 | + True |
| 111 | + >>> x = np.arange(3) |
| 112 | + >>> x |
| 113 | + array([0, 1, 2]) |
| 114 | + >>> x[:, np.newaxis] |
| 115 | + array([[0], |
| 116 | + [1], |
| 117 | + [2]]) |
| 118 | + >>> x[:, np.newaxis, np.newaxis] |
| 119 | + array([[[0]], |
| 120 | + [[1]], |
| 121 | + [[2]]]) |
| 122 | + >>> x[:, np.newaxis] * x |
| 123 | + array([[0, 0, 0], |
| 124 | + [0, 1, 2], |
| 125 | + [0, 2, 4]]) |
| 126 | + |
| 127 | + Outer product, same as ``outer(x, y)``: |
| 128 | + |
| 129 | + >>> y = np.arange(3, 6) |
| 130 | + >>> x[:, np.newaxis] * y |
| 131 | + array([[ 0, 0, 0], |
| 132 | + [ 3, 4, 5], |
| 133 | + [ 6, 8, 10]]) |
| 134 | + |
| 135 | + ``x[np.newaxis, :]`` is equivalent to ``x[np.newaxis]`` and ``x[None]``: |
| 136 | + |
| 137 | + >>> x[np.newaxis, :].shape |
| 138 | + (1, 3) |
| 139 | + >>> x[np.newaxis].shape |
| 140 | + (1, 3) |
| 141 | + >>> x[None].shape |
| 142 | + (1, 3) |
| 143 | + >>> x[:, np.newaxis].shape |
| 144 | + (3, 1) |
| 145 | + |
| 146 | + |
| 147 | +.. data:: pi |
| 148 | + |
| 149 | + ``pi = 3.1415926535897932384626433...`` |
| 150 | + |
| 151 | + .. rubric:: References |
| 152 | + |
| 153 | + https://en.wikipedia.org/wiki/Pi |
0 commit comments