python - Iterating through dictionary and numpy array simultaneously -
is there slick way of iterating through dictionary of objects, calling member function of each object , assigning value numpy array. have following member function code:
# preallocate number of objects in dictionary newtable = numpy.zeros( self.numobj ); item, nt in zip( self.dicttable.values(), newtable ): dt = item.calculatedutycycle() * 100.0 return newtable
this doesn't run because assignment numpy array not done correctly. can correctly using nditer, not sure how combine iterator dictionary table iteration. avoiding traditional 'counter' increment access array there more elegant 'pythonic' solution.
i don't seen advantage using numpy
here, since iterating on regular python list (values()). i'd list comprehension, , convert array later. array 1d. numpy
shines when working multidimensional objects (as opposed simple lists).
list_answer = [item.calculatedutycycle() * 100.0 item in self.dicttable.values()] newtable = np.array(list_answer)
Comments
Post a Comment