When doing:
import numpy
A = numpy.array([1,2,3,4,5,6,7,8,9,10])
B = numpy.array([1,2,3,4,5,6])
A[7:7+len(B)] = B # A[7:7+len(B)] has in fact length 3 !
we get this typical error:
ValueError: could not broadcast input array from shape (6) into shape (3)
This is 100% normal because A[7:7+len(B)] has length 3, and not a length = len(B) = 6, and thus, cannot receive the content of B !
How to prevent this to happen and have easily the content of B copied into A, starting at A[7]:
A[7:???] = B[???]
# i would like [1 2 3 4 5 6 7 1 2 3]
This could be called "auto-broadcasting", i.e. we don't have to worry about length of arrays.
Edit: another example if len(A) = 20:
A = numpy.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
B = numpy.array([1,2,3,4,5,6])
A[7:7+len(B)] = B
A # [ 1 2 3 4 5 6 7 1 2 3 4 5 6 14 15 16 17 18 19 20]