Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.log10

Computes the base-10 logarithm element-wise for array-like input. Negative real values produce NaN, and scalar input produces a scalar result.

How it works

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.

Syntax

numpy.log10(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True, signature=None)

Parameters

NameTypeDescription
xarray_likeInput values.
outndarray, None, or tuple of ndarray and None, optionalDestination for the result; it may be an ndarray, None, or a tuple of ndarray and None. Its shape must support broadcasting with the inputs.
wherearray_like of bool, optionalBoolean selector indicating where to compute.
casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optionalControls casting of operands.
order{‘K’, ‘A’, ‘C’, ‘F’}, optionalMemory layout order for the output.
dtypedtype, optionalOutput data type.
subokbool, optionalIf True, subclasses are passed through.
signature_UfuncSignature, optionalUfunc generalized-signature option.

Returns

ndarray or scalar: the base-10 logarithm of x element-wise; scalar input produces a scalar.

Key points

  • Computes logarithms to base 10 independently for each input element.
  • The x argument accepts array-like input values.
  • out can receive results in caller-provided storage.
  • For array input, the returned values correspond element by element to x.

Common mistakes

  • Negative real inputs produce NaN rather than a real logarithm.
  • Scalar input returns a scalar, so code should not assume the result is always an ndarray.
  • An output array must have a broadcast-compatible shape.

Example: Element-wise base-10 logarithms

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.

When to use it

Log-scale analysis

Transforming positive measurements to logarithmic scale.

Magnitude estimation

Calculating orders of magnitude from numeric arrays.

Conditional element-wise computation

Applying logarithms across masked or conditionally selected array positions.

Interview questions

QWhat does np.log10 compute, and what does it return?

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.

QHow can np.log10 avoid computing at selected positions or reuse storage?

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.

QHow does np.log10 handle special or out-of-domain values?

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.log
  • numpy.log2
  • numpy.emath.log10

Source: numpy.log10. Checked 2026-10-15.