【问题标题】:python 2D array with linspace带有 linspace 的 python 2D 数组
【发布时间】:2015-08-01 09:51:14
【问题描述】:

我想生成 1024x1024 的二维数组,从 (275.79905,64.215746) 到 (275.14172,64.500187) 而不是 (0,0) 到 (1024,1024)。我知道linspace 可以生成它,但是如何使用它制作二维数组?

【问题讨论】:

    标签: python


    【解决方案1】:

    我建议使用meshgrid。这是documentation


    示例

    >>> nx, ny = (3, 2)
    >>> x = np.linspace(0, 1, nx)
    >>> y = np.linspace(0, 1, ny)
    >>> xv, yv = np.meshgrid(x, y)
    >>> xv
    array([[ 0. ,  0.5,  1. ],
           [ 0. ,  0.5,  1. ]])
    >>> yv
    array([[ 0.,  0.,  0.],
           [ 1.,  1.,  1.]])
    

    linspaceargs:

    1. 起始值
    2. 终值
    3. 向量中所有值的个数

    【讨论】:

    • @OP,对于这个特殊的情况(n x n),你可以meshgrid数组本身:meshgrid(x, x)
    猜你喜欢
    • 2014-05-21
    • 2013-05-29
    • 2014-10-17
    • 2022-11-01
    • 2019-06-29
    • 2018-04-06
    • 2015-01-17
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多