bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / shares_memory
_ArrayFunctionDispatcher
numpy:shares_memory
Signature
def shares_memory ( a , b , / , max_work = -1 ) Summary
Determine if two arrays share memory.
Extended Summary
Parameters
a, b: ndarrayInput arrays
max_work: int, optionalEffort to spend on solving the overlap problem (maximum number of candidate solutions to consider). The following special values are recognized:
max_work=-1 (default)
The problem is solved exactly. In this case, the function returns True only if there is an element shared between the arrays. Finding the exact solution may take extremely long in some cases.
max_work=0
Only the memory bounds of a and b are checked. This is equivalent to using
may_share_memory().
Returns
out: bool
Raises
: numpy.exceptions.TooHardErrorExceeded max_work.
Examples
import numpy as np x = np.array([1, 2, 3, 4]) np.shares_memory(x, np.array([5, 6, 7])) np.shares_memory(x[::2], x) np.shares_memory(x[::2], x[1::2])✓
from numpy.lib.stride_tricks import as_strided x = np.zeros([192163377], dtype=np.int8) x1 = as_strided( x, strides=(36674, 61119, 85569), shape=(1049, 1049, 1049)) x2 = as_strided( x[64023025:], strides=(12223, 12224, 1), shape=(1049, 1049, 1)) np.shares_memory(x1, x2, max_work=1000)✓
See also
- may_share_memory
Aliases
-
numpy.shares_memory