infer-actively / pymdp

A Python implementation of active inference for Markov Decision Processes
MIT License
419 stars 83 forks source link

Fix `pymdp.utils.obj_array_from_list` #130

Closed conorheins closed 4 weeks ago

conorheins commented 1 month ago

Creating an object array from a list of numpy arrays seems to break if the component arrays of the list have matching leading axis. For example

arrs = [np.zeros((3, 6)), np.zeros((3, 4, 5))]
obj_arr = np.array(arrs, dtype=object)

will throw the following error:

ValueError: could not broadcast input array from shape (3,6) into shape (3,)

whereas

arrs = [np.zeros((4, 6)), np.zeros((3, 4, 5))]
obj_arr = np.array(arrs, dtype=object)

works just fine.