Open In App

numpy.may_share_memory() function – Python

Improve
Improve
Like Article
Like
Save
Share
Report

numpy.may_share_memory() function determine if two arrays might share memory.

Syntax : numpy.may_share_memory(arr1, arr2, max_work = None)
Parameters :
arr1, arr2 : [ndarray] Input arrays.
max_work : [int, optional] Effort to spend on solving the overlap problem.
Return : [bool] Checking if two arrays might share memory. A return of True does not necessarily mean that the two arrays share any element. It just means that they might.

Code #1 :




# Python program explaining
# numpy.may_share_memory() function
             
# importing numpy as geek 
import numpy as geek 
    
arr1 = geek.array([1, 2, 3, 4])
arr2 = geek.array([5, 6, 7])
   
gfg = geek.may_share_memory(arr1, arr2)
       
print (gfg)


Output :

False

 
Code #2 :




# Python program explaining
# numpy.may_share_memory() function
            
# importing numpy as geek 
import numpy as geek 
   
arr1 = geek.zeros([3, 4])
arr2 = arr1[::1]
  
gfg = geek.may_share_memory(arr1, arr2)
      
print (gfg)


Output :

True

Last Updated : 08 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads