Log-scale analysis
Transforming positive measurements to logarithmic scale.
NumPy · Function
Computes the base-10 logarithm element-wise for array-like input. Negative real values produce NaN, and scalar input produces a scalar result.
np.log10 applies the base-10 logarithm element-wise to array-like input. It returns an ndarray for array input and a scalar for scalar input; negative real values produce NaN, while zero produces negative infinity.
numpy.log10(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True, signature=None)| Name | Type | Description |
|---|---|---|
x | array_like | Input values. |
out | ndarray, None, or tuple of ndarray and None, optional | Destination for the result; it may be an ndarray, None, or a tuple of ndarray and None. Its shape must support broadcasting with the inputs. |
where | array_like of bool, optional | Boolean selector indicating where to compute. |
casting | {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional | Controls casting of operands. |
order | {‘K’, ‘A’, ‘C’, ‘F’}, optional | Memory layout order for the output. |
dtype | dtype, optional | Output data type. |
subok | bool, optional | If True, subclasses are passed through. |
signature | _UfuncSignature, optional | Ufunc generalized-signature option. |
ndarray or scalar: the base-10 logarithm of x element-wise; scalar input produces a scalar.
import numpy as np
x = np.array([1e-15, -3.0, 100.0])
y = np.log10(x)
print(y) # [-15. nan 2.]Computes base-10 logarithms element by element; a negative real input produces nan.
Transforming positive measurements to logarithmic scale.
Calculating orders of magnitude from numeric arrays.
Applying logarithms across masked or conditionally selected array positions.
np.log10 is a NumPy ufunc that computes the base-10 logarithm element-wise. It accepts array-like input and returns an ndarray, or a scalar when the input is scalar.
Follow-up: What happens for a negative real value? It produces NaN; for complex input, the ufunc follows complex logarithm behavior.
The optional where argument selects the positions where computation occurs. The optional out argument lets the result be written into supplied storage instead of allocating a new result.
Follow-up: What constraint applies to out? Its shape must be compatible with the broadcast shape of the inputs.
For real negative inputs, np.log10 returns NaN. Zero produces negative infinity, and positive infinity produces positive infinity as expected for the logarithm.
Follow-up: Which NumPy alternative provides complex principal values for negative real inputs? numpy.emath.log10 does so.
numpy.lognumpy.log2numpy.emath.log10