In [1]:
import numpy as np
In [2]:
a_2d = np.arange(12).reshape(3, 4)
print(a_2d)
In [3]:
a_slice = a_2d[:2, :2]
print(a_slice)
In [4]:
print(np.shares_memory(a_2d, a_slice))
In [5]:
a_slice[0, 0] = 100
print(a_slice)
In [6]:
print(a_2d)
In [7]:
a_2d[0, 0] = 0
print(a_2d)
In [8]:
print(a_slice)
In [9]:
a_fancy_index = a_2d[[0, 1]]
print(a_fancy_index)
In [10]:
print(np.shares_memory(a_2d, a_fancy_index))
In [11]:
a_fancy_index[0, 0] = 100
print(a_fancy_index)
In [12]:
print(a_2d)
In [13]:
a_slice_copy = a_2d[:2, :2].copy()
print(a_slice_copy)
In [14]:
print(np.shares_memory(a_2d, a_slice_copy))
In [15]:
a_slice_copy[0, 0] = 100
print(a_slice_copy)
In [16]:
print(a_2d)
In [17]:
a_fancy_index_slice = a_2d[[0, 1], :3]
print(a_fancy_index_slice)
In [18]:
print(np.shares_memory(a_2d, a_fancy_index_slice))
In [19]:
a_scalar_slice = a_2d[1, :3]
print(a_scalar_slice)
In [20]:
print(np.shares_memory(a_2d, a_scalar_slice))