0

In the code below, I am trying to keep the array elements as tuples.

>>> a = np.int32([(1, 2), (3, 4)])
>>> a
array([[1, 2],
       [3, 4]], dtype=int32)

>>> np.mean(a[:, 0], axis=0)
>>> np.mean(a[:, 1], axis=0)

Where things break is when I am trying to add more elements.

>>> a = np.append(a, ([4, 5]))
>>> a
array([1, 2, 3, 4, 4, 5])

How can I keep the array in the same way, so I am still able to reference the first and second values of each of its element's tuples?

John Difool
  • 5,572
  • 5
  • 45
  • 80

1 Answers1

0

Try

a = np.append(a, [4, 5], axis=0)

and take a look at axis param in docs

Slam
  • 8,112
  • 1
  • 36
  • 44
  • I just tried and I am getting 'ValueError: all the input arrays must have same number of dimensions'. And I keep banging my head on axis, trying to understand what it the basic behavior without it. I get the 0 in the Y direction and 1 in the X direction in 2D components, but isn't axis 0 by default in this case? – John Difool Mar 06 '18 at 01:15
  • 1
    You need a = np.append(a, [(4, 5)], axis=0). default is axis=None – skmth Mar 06 '18 at 02:49