Skip to content Skip to sidebar Skip to footer

Creating Numpy Array Problem ( Could Not Broadcast Input Array From Shape (2) Into Shape (1) )

what's the problem with creating this numpy array np.array( [np.array([1]), np.array([ [1,2] ])] ) # Error: could not broadcast input array from shape (2) into shape (1) but no

Solution 1:

If the final output can be a 1D vector, np.append might do the trick:

np.append(np.array([1]),np.array([[1,2]]))

If each element of the final desired array is a different dimension, do you need it to be a numpy object? a list should work final = [np.array([1]), np.array([ [1,2], [1,2] ])]

Post a Comment for "Creating Numpy Array Problem ( Could Not Broadcast Input Array From Shape (2) Into Shape (1) )"