0

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.

H. Minear
  • 87
  • 1
  • 8
  • What sort of access do you have to the remote machine? Is this on a network share, or via http / ftp, or can you ssh to it? – Hugh Bothwell Jun 20 '17 at 15:06
  • Your python script somehow needs access to these files. https://stackoverflow.com/questions/1035340/reading-binary-file-and-looping-over-each-byte – Gillespie Jun 20 '17 at 15:23
  • @H.Minear I'm not sure I quite understand. The python script and the files you want to process need to be on the same machine. You can either scp your python script to the remote machine, or scp the remote files to your local machine. – Gillespie Jun 20 '17 at 15:41

1 Answers1

1

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)
Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99