ianhbell / binfit

The python code for fitting interaction parameters for binary mixtures
6 stars 0 forks source link

Type Error in binary_fitter.py :: Can only assign array (not "list") to array slice #1

Closed jurgenolivier closed 4 years ago

jurgenolivier commented 4 years ago

Dear Ian,

I was hoping that would please be able to assist me with a small problem I encounter in binary_fitter.py on line 153, namely: "TypeError: can only assign array (not "list") to array slice"

As per your guidelines provided in the repository, after installing Anaconda I can get as far as:

  1. Creating new environment "py3", and loading pandas, numpy, and scipy into this environment,
  2. Activating the newly created py3 in the Anaconda terminal,
  3. Next I can: pip install deap, CoolProp, xlrd, ctRefprop,
  4. Then I add an extra step to change the directory in the terminal to the folder where I keep all the files downloaded from the repository (cd C:\Users\USERNAME\Desktop\binfit-master),
  5. Then I call binary_fitter.py from the terminal, which runs to line 153 before hitting the error described above (please see traceback below for more information)?

There doesn't seem to be any problem finding os.environ['RPPREFIX'] (...if I print the prefix to the terminal the path is correct), and so I have not needed to un-comment the associated line in the procedure "main" of binary_fitter.py

Below the traceback given by the terminal:

(py3) C:\Users\USERNAME\Desktop\binfit-master>python binary_fitter.py
number of unique T: 33 number of unique x: 82 only_fit_gammaT: False
Traceback (most recent call last):
  File "binary_fitter.py", line 489, in <module>
    deap_optimizer(collect_binary(lib, ('DECANE','PROPANE')))
  File "binary_fitter.py", line 461, in deap_optimizer
    timeout = 7200)
  File "binary_fitter.py", line 299, in eaSimple
    for ind, fit in zip(invalid_ind, fitnesses):
  File "C:\Users\USERNAME\AppData\Local\Continuum\anaconda3\envs\py3\lib\site-packages\deap\tools\constraint.py", line 49, in wrapper
    return func(individual, *args, **kwargs)
  File "binary_fitter.py", line 392, in evalOneMax
    err = apply_betagamma(df, parameters, '', Nloops = 100, Npoints_selected = 5, fit_bits = fit_bits)
  File "binary_fitter.py", line 176, in apply_betagamma
    set_parameters(RP, parameters)
  File "binary_fitter.py", line 153, in set_parameters
    fij[0:len(parameters)] = parameters
TypeError: can only assign array (not "list") to array slice

If I insert on line 152 of binary_fitter.py the code “print(len(parameters))” I get “5”, and for “print(parameters)” I get “[0.9239701215168029, 3.405018302953891, 1, 1, 0]”

Thanks for making this code available!

Regards, Jurgen Olivier

ianhbell commented 4 years ago

Yup, I fixed this problem in 6ea37d1c4ff927df8296616f113681d26bc2ad3a