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

NumPy · Pipe

ndarray.real

Returns the real part of an ndarray. It usually provides a view into the source array, while object arrays use each element’s .real value.

How it works

Accessing ndarray.real extracts the real component of every array element. For most numeric arrays it usually provides a view into the original array; object arrays instead obtain each element’s .real value individually.

Syntax

ndarray.real

Returns

The real part of the array; usually a view for ordinary numeric arrays and elementwise .real values for object arrays.

Key points

  • ndarray.real extracts the real component of an ndarray.
  • For standard numeric arrays, the result generally shares the source array’s data through a view.
  • Object-dtype arrays obtain each element’s real value individually.
  • numpy.real is the documented function equivalent of the ndarray.real attribute.

Common mistakes

  • The result is generally a view, but object-dtype arrays are handled element by element, so view-based assumptions do not apply.

Example: Read real components from a complex array

import numpy as np

x = np.sqrt([1 + 0j, 0 + 1j])
real_parts = x.real

print(real_parts)
# [1.         0.70710678]
print(real_parts.dtype)
# float64

Extracts the real component of each complex array element.

When to use it

Extract complex real components

Separate amplitudes from complex-valued numerical data.

Analyze computed results

Inspect the real values produced by complex-valued NumPy expressions.

Convenient attribute access

Use the array’s real component without an explicit conversion function.

Interview questions

QWhat does ndarray.real provide?

ndarray.real is an attribute that returns the array’s real part. For a complex array, each value contributes its real component while preserving the array’s shape.

Follow-up: How does it behave for object arrays? It evaluates .real elementwise rather than using the usual view behavior.

QDoes ndarray.real copy the data?

For ordinary numeric arrays, ndarray.real usually returns a view into the original array rather than copying the data. This can make access efficient and means the result may share storage with the source.

Follow-up: What exception does the documentation identify? Object arrays return elementwise .real values instead of the usual view into the original array.

QHow is ndarray.real related to numpy.real?

The attribute is accessed as x.real, where x is an ndarray. It is useful for separating real components from complex-valued data without calling a separate function.

Follow-up: What equivalent function does NumPy document? numpy.real is the equivalent function.

  • numpy.real
  • ndarray.imag

Source: numpy.ndarray.real — NumPy v2.5 Manual. Checked 2026-10-15.