Dynamic Access Of Multi Dimensional Python Array
I am a python newbie. I was confused on how to access array element dynamically. I have a list b= [1,2,5,8] that I dynamically obtain so its length can vary. With help of this lis
Solution 1:
if the dimensions are [1,2,5,8]
you can use numbers 0, 0..1, 0..4, 0..7
for each dimension.
Numpy lets you access positions with tuples:
shape = [1, 2, 5, 8]
pos = [0, 1, 1, 3]
my_array = np.ones(shape)
my_array[tuple(pos)] # will return 1
Post a Comment for "Dynamic Access Of Multi Dimensional Python Array"