Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: zip argument #2 must support iteration

I got an error TypeError: zip argument #2 must support iteration.

data = libraries.pd.read_csv('a.csv',header=1, parse_dates=True)
datas = DataCleaning.DataCleaning(data)
datas.cleaning(media)

calDf = datas.getDatas()

array_x = libraries.np.int32(libraries.np.zeros(len(calDf)))
array_y = libraries.np.int32(libraries.np.zeros(len(calDf)))


if len(calDf) > 1:
    for num in range(len(calDf)):
        array_x[num] = calDf.iloc[num,0]
        array_y[num] = calDf.iloc[num,1]

    def nonlinear_fit(x,a,b):
        return  b * libraries.np.exp(x / (a+x))

    prameter_initial = libraries.np.array([0,0])

    try:
        param, cov = libraries.curve_fit(nonlinear_fit, array_x, array_y, maxfev=5000)

    except RuntimeError:
        print("Error - curve_fit failed")

li_result = []
li_result = zip(y, array_x, array_y)

I think the part of zip(y, array_x, array_y) is wrong because zip's arguments are not list type,so I wrote

for i in y:
 li_result = []
 li_result = zip(y, array_x[i], array_y[i])

but I got an error,

li_result = zip(y, array_x[i], array_y[i])
IndexError: only integers, slices (`:`), ellipsis (`...`),
numpy.newaxis (`None`) and integer or boolean arrays are valid indices

So, I cannot understand how to fix this. What should I do?

like image 573
user21063 Avatar asked Mar 22 '17 05:03

user21063


1 Answers

It sounds like you have three arrays itemNameList, array_x, and array_y

Assuming they are all the same shape, you can just do:

zipped = zip(itemNameList,array_x,array_y)
li_result = list(zipped)

EDIT

Your problem is that array_x and array_y are not actual numpy.array objects, but likely numpy.int32 (or some other non-iterable) objects:

array_x = np.int32(np.zeros(None))
array_x.shape
# ()
array_x.__iter__
# AttributeError: 'numpy.int32' object has no attribute '__iter__'

Perhaps their initialization is not going as expected, or they are being changed from arrays somewhere in your code?

like image 126
Crispin Avatar answered Nov 06 '22 04:11

Crispin