I have the the following array
import numpy as np
import CustomClass
# Total = 24
height = 4
width = 6
a = np.empty((height, width), dtype=object)
for row in range(self.height):
for col in range(self.width):
self.a[row, col] = CustomClass()
I would like to change the attribute for part of the array (filled with my custom class). For example, I would like to change 12 elements starting from element[0,0], then from row to row. Ideally, I would do something comparable to
change=11
for i in range(change):
a[i].value=True
The result would be something like the following (0: unchanged, x: changed)
x x x x x x
x x x x x 0
0 0 0 0 0 0
0 0 0 0 0 0
The problem with my array is that I first need to flatten it before I could do something like this. Or I should calculate how many columns and rows I before I can index the array itself. Is there a numpy function such that I can just iteratre over the array element by element (row by row).
I hope my explanation is clear?
full_array[0:change] = new_valuesas long as the shapes match