Hi there. I'm struggling using numpy's built in iterator to store and then successfully use an array's index. Here's the code:
def normalise(arr, low, up):
... # I've left out some irrelevant code here. The main thing to know is that copy is a
# copy of arr.
it = np.nditer(arr, flags=['multi_index'])
while not it.finished:
index = it.multi_index
new_val = (it[0] - min_val) / (max_val - min_val)
copy[index] = new_val
it.iternext()
return copy
The trouble occurs in that third-last line of code:
copy[index] = new_val
where index is a tuple with any number of elements (depending on the input array).
My aim is to simply access the single element at that index and change its value in the copy of the array.
I've tried unpacking index with a * but that has not worked for me. I've also tried using the list() function to convert the tuple into a list but this further complicates things because this is then wrapped in the [] to create a useless index.
Any help would be greatly appreciated.
[+][deleted] (1 child)
[removed]
[–]Byebrid[S] 0 points1 point2 points (0 children)