In [1]:
import numpy as np
In [2]:
a = np.arange(6).reshape(1, 2, 1, 3, 1)
print(a)
In [3]:
print(a.shape)
In [4]:
a_s = np.squeeze(a)
print(a_s)
In [5]:
print(a_s.shape)
In [6]:
print(np.shares_memory(a, a_s))
In [7]:
a_s_copy = np.squeeze(a).copy()
In [8]:
print(np.shares_memory(a, a_s_copy))
In [9]:
print(np.squeeze(a, 0))
In [10]:
print(np.squeeze(a, 0).shape)
In [11]:
# print(np.squeeze(a, 1))
# ValueError: cannot select an axis to squeeze out which has size not equal to one
In [12]:
# print(np.squeeze(a, 5))
# AxisError: axis 5 is out of bounds for array of dimension 5
In [13]:
print(np.squeeze(a, -1))
In [14]:
print(np.squeeze(a, -1).shape)
In [15]:
print(np.squeeze(a, -3))
In [16]:
print(np.squeeze(a, -3).shape)
In [17]:
print(np.squeeze(a, (0, -1)))
In [18]:
print(np.squeeze(a, (0, -1)).shape)
In [19]:
# print(np.squeeze(a, (0, 1)))
# ValueError: cannot select an axis to squeeze out which has size not equal to one
In [20]:
print(a.squeeze())
In [21]:
print(a.squeeze().shape)
In [22]:
print(a.squeeze((0, -1)))
In [23]:
print(a.squeeze((0, -1)).shape)
In [24]:
a_s = a.squeeze()
print(a_s)
In [25]:
print(np.shares_memory(a, a_s))
In [26]:
print(a)