24 lines
624 B
Python
24 lines
624 B
Python
import numpy as np
|
|
|
|
'''array_1d_1 = np.array([1, 4, 6, 2, 9, 10, 11])
|
|
# Assigning an array to the slice of array_1d
|
|
array_1d_1[2:] = np.array([3, 5, ])
|
|
print(array_1d_1)
|
|
|
|
|
|
import numpy as np
|
|
|
|
arr = np.zeros((5,))
|
|
arr[:] = np.array([1, 2]) # ❌ ValueError
|
|
|
|
|
|
np.zeros((5)) # Interpreted as np.zeros(5), returns a 1D array of size 5
|
|
np.zeros((5,)) # Explicitly a tuple, also returns a 1D array of size 5
|
|
'''
|
|
|
|
print(np.zeros((5)))
|
|
print(np.zeros((5,)))
|
|
print(np.zeros((5, 1))) # 2D array with shape (5, 1)
|
|
print(np.zeros((5, 2))) # 2D array with shape (5
|
|
|
|
print(np.full((5, 5), 1)) # 2D array of 1's with shape (5, 5) |