简体   繁体   中英

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. 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 .

import numpy as np

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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