-1

I am trying to make a raster plot from neuronal activity. I starred the time of the neuronal activity in lists. Lets say:

Event1 = [[-.1,0.1,3],[-2,1,4,4.5,4.6,4.9]]
Event2 = [[1,2]]

What I would like in order to make the raster is to get all the elements from each event in a new list. Specifically

raster = [[-.1,0,1,3],[-2,1,4,4.5,4.6,4.9],[1,2]]

I thought into use np.concatenate but in the cases there is an event like Event2 this shields an error

raster = np.concatenate([Event1,Event2])

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimension(s)

While if for instance Event3 = [[-1,-.1,3],[1,2]] this performs well

raster = np.concatenate([Event1,Event3])
array([list([-0.1, 0.1, 3]), list([-2, 1, 4, 4.5, 4.6, 4.9]),list([-1, -0.1, 3]), list([1, 2])], dtype=object)

How can I solve this?

Lorenzo Gutiérrez
  • 105
  • 1
  • 1
  • 10
  • You cannot have non-rectangular arrays in numpy. You have to use either array of arrays or array of lists instead, which in that case begs the question of why not simply use lists: `raster =[list(Event1), list(Event2)]` and use `.append` to concatenate more lists to `raster`. – Ehsan Jan 22 '21 at 20:56

1 Answers1

0

Something like this:

Event1 = [[-.1,0.1,3],[-2,1,4,4.5,4.6,4.9]]
Event2 = [[1,2]]
Event3 = [[-1,-.1,3],[1,2]]

Event1.extend(Event2)
Event1.extend(Event3)
print(Event1)

Output:

[[-0.1, 0.1, 3], [-2, 1, 4, 4.5, 4.6, 4.9], [1, 2], [-1, -0.1, 3], [1, 2]]
Tola
  • 254
  • 3
  • 17