Given a numpy array with multiple arrays inside, how do I replace all the values of the array with values from another array?
For example:
import numpy
first_array = numpy.array([[1,2],[3,4],[5,6],[7,8],[9,10]])
second_array = numpy.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
0.7, 0.8, 0.9, 1])
Given these arrays, How do I replace 1,2 with 0.1, 0.2 and etc?
first_array = second_array.reshape((5,2))is the easy way. As long as the total number of elements is the same, just reshape it.second_arraydirectly?first_array.shapethan hard-code(5,2). [EDIT: I now see that an answer has been posted, which does exactly this.]first_arraydtype isint, so you can't put floats in it. In any case reshaping the 2nd array is more efficient.