I'm trying to develop a class that behaves as a list of lists. I need it to pass it as a type for an individual, in deap framework. Presently, I'm working with numpy object array. Here is the code.
import numpy
class MyArray(numpy.ndarray):
def __init__(self, dim):
numpy.ndarray.__init__(dim, dtype=object)
But when I try to pass values to the object of MyArray
,
a = MyArray((2, 2))
a[0][0] = {'procID': 5}
I get an error,
Traceback (most recent call last):
File "D:/PythonProjects/NSGA/src/test.py", line 23, in <module>
'procID': 5
TypeError: float() argument must be a string or a number, not 'dict'
Any suggestions are welcome. You can also show me a different way without making use of numpy which facilitates type creation.
A similar question can be found here