Vectorized NumPy linspace across multi-dimensional arrays

后端 未结 2 1843
栀梦
栀梦 2020-12-11 18:11

Say I have 2 numpy 2D arrays, mins, and maxs, that will always be the same dimension as one another. I\'d like to create a third array, results, that is the result of apply

2条回答
  •  感动是毒
    2020-12-11 19:09

    As of Numpy version 1.16.0, non-scalar start and stop are now supported.

    So, now you can do this:

    assert np.__version__ > '1.17.2'
    
    mins = np.random.rand(2,2)
    maxs = np.random.rand(2,2)
    
    # Number of elements in the linspace
    x = 3
    
    results = np.linspace(mins, maxs, num=x)
    
    # And, if required
    results = np.rollaxis(results, 0, 3)
    

提交回复
热议问题