简体   繁体   中英

Looping through numbers in Python

I need to loop through two lists that each contain integers.

What functions should I use to loop through 2 lists in Python? I am working on a Linux machine.

Sounds like you aren't using scp properly - see https://unix.stackexchange.com/questions/188285/how-to-copy-a-file-from-a-remote-server-to-a-local-machine

Depending on what the remote machine makes available, you could run the script there and just get the results; this might be more efficient.

You are pretty vague about the actual operation you want to perform; if you want to deal with a lot of data quickly NumPy might really help - something like

import numpy as np

FILES = ["a.dat", "b.dat"]    # we assume that all files are the same length

data = np.stack(
    (np.fromfile(f, dtype=np.uint32) for f in FILES),   # endian-ness may be an issue!
    axis=1
)

# applying a Python function
def myfunc(row):
    return min(row)
result = np.apply_along_axis(myfunc, 1, data)

# but using a numpy function directly would be better!
result = np.min(data, axis=1)

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