Skip to content Skip to sidebar Skip to footer

Iterating Over A Numpy Array With Enumerate Like Function

I want to numpy arrays into some of my code. I am trying to iterate over an array. import numpy as np a=10.0 b=55.0 y=np.asarray([11,30,54,7,22,5,15,65,15,6]) I =[y[i] / (a + (i

Solution 1:

You can do it without loop with np.arange:

>>> c = a + b*(np.arange(1, len(y)+1))
>>> y/c
array([ 0.16923077,  0.25      ,  0.30857143,  0.03043478,  0.07719298,
        0.01470588,  0.03797468,  0.14444444,  0.02970297,  0.01071429])

Post a Comment for "Iterating Over A Numpy Array With Enumerate Like Function"