Combinations from range of values for given sizes

后端 未结 3 522
误落风尘
误落风尘 2021-01-14 18:39

I\'m using the following code to create a list of indices for an array. However, I would like the index to run in Fortran order i.e. the inner loop being the faster varying

3条回答
  •  [愿得一人]
    2021-01-14 19:24

    A general solution (that would work for higher dimensional indices e.g. 3D, 4D) etc. seems to be as suggested in the comments by Nils Werner:

    points = [32,30]
    np.transpose(np.nonzero(np.ones(points[::-1])))[:,::-1]
    

    Output:

    array([[ 0,  0],
           [ 1,  0],
           [ 2,  0],
           ..., 
           [29, 29],
           [30, 29],
           [31, 29]])
    

提交回复
热议问题