2017-05-10 16 views
4

アメリカ全体の温度の時系列を表す3Dマスク配列を持っているといいます。[Time, Lat, Lon]私は100の異なる場所の表の時系列を取得したい。かすかな索引付けをすると、[:, [lat1, lat2...], [lon1, lon2...]]のようになります。ダスク配列は、この種の索引付けをまだ許可していません。制限を与えてこのタスクを達成する最善の方法は何ですか?ダスクアレイのn個の個別の要素のスライシング

答えて

4

インデクサvindexを使用する。

In [1]: import dask.array as da 

In [2]: import numpy as np 

In [3]: x = np.arange(1000).reshape((10, 10, 10)) 

In [4]: dx = da.from_array(x, chunks=(5, 5, 5)) 

In [5]: xcoords = [1, 3, 5] 

In [6]: ycoords = [2, 4, 6] 

In [7]: x[:, xcoords, ycoords] 
Out[7]: 
array([[ 12, 34, 56], 
     [112, 134, 156], 
     [212, 234, 256], 
     [312, 334, 356], 
     [412, 434, 456], 
     [512, 534, 556], 
     [612, 634, 656], 
     [712, 734, 756], 
     [812, 834, 856], 
     [912, 934, 956]]) 

In [8]: dx.vindex[:, xcoords, ycoords].compute() 
Out[8]: 
array([[ 12, 112, 212, 312, 412, 512, 612, 712, 812, 912], 
     [ 34, 134, 234, 334, 434, 534, 634, 734, 834, 934], 
     [ 56, 156, 256, 356, 456, 556, 656, 756, 856, 956]]) 

いくつかの注意点:これは、点状の索引付けまたは完全スライスのみ受け付け

  • このない(まだ)numpyのアレイで使用可能にするが、提案されています。提案書hereを参照してください。

  • 新しい軸が常に前面に配置されるため、これはnumpyのファンシーインデックスとは完全には互換性がありません。シンプルtransposeはこれらかかわらをrearangeことができます。

例:

In [9]: dx.vindex[:, xcoords, ycoords].T.compute() 
Out[9]: 
array([[ 12, 34, 56], 
     [112, 134, 156], 
     [212, 234, 256], 
     [312, 334, 356], 
     [412, 434, 456], 
     [512, 534, 556], 
     [612, 634, 656], 
     [712, 734, 756], 
     [812, 834, 856], 
     [912, 934, 956]]) 
関連する問題