Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. #2

Open
PengleiGao opened this issue May 3, 2024 · 1 comment

Comments

@PengleiGao
Copy link

Hi, when I use the package, I have the following issues:
code is:
d1 = np.random.rand(100,10)
d2 = np.random.rand(100,10)
d3 = np.random.rand(100,10)
data = [d1,d2,d3]
params = pyrea.parea_2_genetic(data, k_min=2, k_max=5)

it returns the error:
TypeError Traceback (most recent call last)
Cell In[14], line 1
----> 1 params_hierarchical = pyrea.parea_1_genetic(data, k_min=2, k_max=5, k_final=3, n_generations=10, n_population=10)

File ~/anaconda3/envs/eval/lib/python3.10/site-packages/pyrea/core.py:833, in parea_1_genetic(data, k_min, k_max, k_final, n_population, n_generations)
830 stats.register("max", np.max)
832 # Run the genetic algorithm
--> 833 pop, log = algorithms.eaSimple(population, toolbox, cxpb=0.7, mutpb=0.2, ngen=n_generations, stats=stats, halloffame=hall_of_fame, verbose=True)
835 print(f"\nSummary:\n{log}")
837 return hall_of_fame[0]

File ~/anaconda3/envs/eval/lib/python3.10/site-packages/deap/algorithms.py:151, in eaSimple(population, toolbox, cxpb, mutpb, ngen, stats, halloffame, verbose)
149 invalid_ind = [ind for ind in population if not ind.fitness.valid]
150 fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
--> 151 for ind, fit in zip(invalid_ind, fitnesses):
152 ind.fitness.values = fit
154 if halloffame is not None:

File ~/anaconda3/envs/eval/lib/python3.10/site-packages/pyrea/core.py:795, in parea_1_genetic..evaluate(individual)
792 with warnings.catch_warnings():
793 warnings.simplefilter("ignore")
--> 795 sil = parea_1(data,
796 individual[0],
797 individual[1],
...
839 xp, is_array_api_compliant = get_namespace(array)
841 # store reference to original array to check if copy is needed when
842 # function returns
TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray.

Do you know how to fix it?
Thanks.

@mdbloice
Copy link
Owner

mdbloice commented May 3, 2024

Hi @PengleiGao

yeah this is because I used the numpy.matrix class and this now deprecated in newer versions of NumPy. I would need to change Pyrea's code to use the numpy.array class instead. Which is on the agenda, and I will do so in the coming days actually. Once I have made the changes, I will update the package and let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants