I am trying the following commands in Numpy. An error is reported on assigning new sequence to the array slice. The error is expected, however I could not figure out why dimension is reported in error. Why is dimension 3 reported in error, the array is of 1-dimension
b = np.array([1, 2, 3, 4, 5])
print(b.ndim) # returns 1
b[2:] = [3, 4, 5, 6, 7]
>> ValueError: cannot copy sequence with size 5 to array axis with dimension 3
arrayis given bynp.shape(array)b[2:]has space for 3 elements. You could assign a list of size 3, or a scalar, or an array of the right size.