python - How to get these shapes to line up for a numpy matrix -
i'm trying input vectors numpy matrix doing:
eigvec[:,i] = null
however keep getting error:
valueerror: not broadcast input array shape (20,1) shape (20)
i've tried using flatten
, reshape
, nothing seems work
the shapes in error message clue.
in [161]: x = np.zeros((10,10)) in [162]: x[:,1] = np.ones((1,10)) # or x[:,1] = np.ones(10) in [163]: x[:,1] = np.ones((10,1)) ... valueerror: not broadcast input array shape (10,1) shape (10) in [166]: x[:,1].shape out[166]: (10,) in [167]: x[:,[1]].shape out[167]: (10, 1) in [168]: x[:,[1]] = np.ones((10,1))
when shape of destination matches shape of new value, copy works. works in cases new value can 'broadcasted' fit. not try more general reshaping. note indexing scalar reduces dimension.
Comments
Post a Comment