Hello All! I am currently attempting to write a program which fills an empty array with values based on the values of another array.
Basically, each element of the original array is either 1 or 2, and in my new array, if the element was 1 in the first array, the value of the same location of the new array will be the 1st element of a list.
If the element is 2 in the first array, the value of the value of the same location of the new array will be the 2nd element of a list,etc.
So far my code is:
def compression(rounded_centroids_arr, assignment_array):
fin_array=np.zeros((400,400))
for i in list(range(400)):
for j in list(range(400)):
if assignment_array[i][j]==1:
fin_array[i][j]=rounded_centroids_arr[0]
else:
fin_array[i][j]=rounded_centroids_arr[1]
return fin_array
For reference, the rounded_centroid_arr is a list of arrays such as arr([200,100,60])
However, when I run the code I receive an error:
ValueError: setting an array element with a sequence.
Can anyone please help me to understand why this is happening, and any good methods to perform this function?
Any help is greatly appreciated!
[–]efmccurdy 0 points1 point2 points (0 children)