sct_2015
sct_2015

Reputation: 29

Python - TypeError: zip argument #1 must support iteration

I have the following code:

import numpy as np
import scipy as sp
import itertools
import os

rootdir = 'mydir'; # mydir changed from actual directory

data = []

for i in range(1, 35):
    data = []
    chari = str(i)+'/';
    newdir = rootdir+chari
    print newdir
    for root, dirs, files in os.walk(newdir):
        for fname in files:
            if fname == 'tc.out':
                with open(os.path.join(root,fname)) as f:
                    lines_after_2 = f.readlines()[2:]
                    for line in lines_after_2:
                        fields = line.split()
                        rowdata = map(float,fields)
                        data.extend(rowdata)
                        column = zip(*rowdata)
                        for index, column in enumerate(columns):
                            print "In column %s, Max = %s, Min = %s" % (index, max(column), min(column))

I am attempting to find the MAXIMUM and MINIMUM value per column (my real goal is to find the max and min for every column but the first, but I'll try to tackle that later).

Upon running this code, I get the following error:

TypeError: zip argument #1 must support iteration

This is how my data is structured:

variables = time T_1 T_2 T_3 T_4 T_5
# 5
3.0100000000e+03  3.0349158928e+02 3.0171422239e+02 2.9770226435e+02 2.9657072961e+02 2.9707000000e+02
3.0125798902e+03  3.0334549013e+02 3.0152263068e+02 2.9799460866e+02 2.9662883748e+02 2.9706572397e+02
3.0175798902e+03  3.0324699921e+02 3.0138079877e+02 2.9821459880e+02 2.9667166944e+02 2.9706245240e+02
3.0225798902e+03  3.0336015983e+02 3.0128802830e+02 2.9836039823e+02 2.9670134577e+02 2.9706003491e+02

I'm attempting to skip over the first two lines, then read the columns and pick out the max and min values.

What's going on here?

Upvotes: 2

Views: 4716

Answers (1)

Kasravnd
Kasravnd

Reputation: 107337

You need to change column = zip(*rowdata) to column = zip(*data).Also as says in comment you should use append instead of extend :

rowdata = map(float,fields)
data.append(rowdata)
column = zip(*data)

Upvotes: 1

Related Questions