python - Populating Array with an indexed array -
i have numpy array called "precip" shape (2,3,3) corresponds (time, lat, lon)
array([[[ 0.05368402, 0.43843025, 0.09521903], [ 0.22627141, 0.12920409, 0.17039465], [ 0.48148674, 0.59170703, 0.41321763]], [[ 0.63621704, 0.11119242, 0.25992372], [ 0.67846732, 0.3710733 , 0.25641174], [ 0.1992151 , 0.86837441, 0.80136514]]])
i have numpy array called "idx" list of indices, shape (3, 4):
array([[0,0,1,1], # time [0,2,0,2], # x coordinate [0,2,0,2]]) # y coordinate
so far have been able index "precip" variable "idx" variable array shape (4,), ie.
>>>accum = precip[idx[0,:],idx[1,:],idx[2,:]] array([ 0.05368402, 0.41321763, 0.63621704, 0.80136514])
but, need array of zeros "accum" shape (3,3), populated sum of "precip" each pair of coordinates in "idx". other gridpoints not listed in "idx" 0.
basically want array "accum" looks this
>>>accum array([[[ 0.68990106, 0. , 0. ], # 0.68990106 = 0.05368402 + 0.63621704 [ 0. , 0. , 0. ], [ 0. , 0. , 1.21458277], # 1.21458277 = 0.41321763 + 0.80136514
i'd appreciate help! :)
if understand correctly need is:
array = [0.5] * 249
it return array of length 249 populated 0.5 in each index. after can slice if necesary retrieve amount of elements like.
if not want, can use dictionaries , add key tuple want way.
dict = {(40, 249): array}
i hope helps.
Comments
Post a Comment