简体   繁体   English

在 python 中将数据从向量移动到二维数组的更快方法?

[英]Faster way to move data from a vector to a 2d array in python?

This is my current code:这是我当前的代码:

#move data from vector, A, into 2D array, H
    for i in range(0,nlat):
        jmin = nheader+1+i*nlon
        jmax = nheader+(i+1)*nlon
        A = A[jmin:jmax+1]
        H[i] = A
        A = np.array(Alist)

I have a very long vector, and I am taking certain data from it and putting it into a 2D array of dimension nlat x nlon.我有一个很长的向量,我从中获取某些数据并将其放入维度为 nlat x nlon 的二维数组中。 This setup works but it is very time consuming.此设置有效,但非常耗时。 Any suggestion of how to speed it up or rewrite it so it doesn't take as long would be very helpful.任何关于如何加快或重写它的建议都将非常有帮助。

You can use numpy .您可以使用numpy

import numpy as np

vector = np.array(A).reshape(nlat, nlon)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM