flopscope.

flopscope.numpy.array_equal

fnp.array_equal(a1, a2, equal_nan=False)[flopscope source][numpy source]

True if two arrays have the same shape and elements, False otherwise.

Adapted from NumPy docs np.array_equal

Areacore
Typecustom
Cost
per-operation
Flopscope Context

Element-wise equality; cost = numel(a).

Parameters

a1, a2:array_like

Input arrays.

equal_nan:bool

Whether to compare NaN's as equal. If the dtype of a1 and a2 is complex, values will be considered equal if either the real or the imaginary component of a given value is nan.

Returns

b:bool

Returns True if the arrays are equal.

See also

Examples

>>> import flopscope.numpy as fnp
>>> flops.array_equal([1, 2], [1, 2])
True
>>> flops.array_equal(flops.array([1, 2]), flops.array([1, 2]))
True
>>> flops.array_equal([1, 2], [1, 2, 3])
False
>>> flops.array_equal([1, 2], [1, 4])
False
>>> a = flops.array([1, flops.nan])
>>> flops.array_equal(a, a)
False
>>> flops.array_equal(a, a, equal_nan=True)
True

When equal_nan is True, complex values with nan components are considered equal if either the real or the imaginary components are nan.

>>> a = flops.array([1 + 1j])
>>> b = a.copy()
>>> a.real = flops.nan
>>> b.imag = flops.nan
>>> flops.array_equal(a, b, equal_nan=True)
True