reciprocal
Syntax
reciprocal(X)
Details
Return element-by-element reciprocal of X. The data type of the result is always DOUBLE.
DolphinDB's reciprocal and NumPy's numpy.reciprocal
are mathematically equivalent, but they handle integer inputs differently. NumPy
preserves the integer dtype, so 1/2 evaluates to 0; whereas DolphinDB automatically
performs floating-point computation and returns 0.5. For example, In Dolphindb,
reciprocal([1,2, 4]) returns [1,0.5,0.25], while
np.reciprocal([1, 2, 4]) returns [1,0,0]. If NumPy uses
floating-point input data, its result is consistent with DolphinDB.
Parameters
X is a scalar/vector/matrix.
Examples
reciprocal(10);
// output: 0.1
reciprocal(1 2 4 8);
// output: [1,0.5,0.25,0.125]
reciprocal(1 2 4 8$2:2);
| #0 | #1 |
|---|---|
| 1 | 0.25 |
| 0.5 | 0.125 |
