I am working on my first agent-based model (abm) in my life and I have to do operations on an array of arrays. Each agent of my model is an array with numbers that are added by the algorithm when certain conditions are met. Sometimes I have to divide or multiply all arrays by the same number. I saw in numpy array I can do this:
vector = np.array([1, 2.1, 3])
when I do
2 / vector
gives me, as expected, array([ 2. , 0.95238095, 0.66666667])
.
But if I want an array of arrays like for example
arrayofarrays = np.array([[1,2,3],[1.1,6],[1]])
it has by default dtype=object
and I guess it is this that doesn't allow me to do
2 / arrayofarrays
which gives
unsupported operand type(s) for /: 'int' and 'list'
Also
2 / arrayofarrays[0]
gives same error. Instead if you use a single array's value, as
2/arrayofarrays[0][1]
it works: 1.0
.
Can you help me? Thanks