1

I'm fairly new to numpy arrays, so any help will be much appreciated.

I want to get a single slice of an n x m array along the second axis, with the result being an n x 1 array, e.g.

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

Then I want:

some_function(a, 0) = array([[1], [4]])  # to get slice of a, along index 0

I've tried a[:, 0] which gives array([1, 4]).

And:

np.transpose(a[:, 0])

also gives:

array([1, 4])

Which confuses me.

I'm sure this is really simple but can't find the correct some_function!

sjm220
  • 11
  • 2

1 Answers1

0

So I've solved it with np.reshape:

some_function(a,0) = np.reshape(a[:,0],(2,1))

But this doesn't seem too elegant. Anyone got a neater solution?

sjm220
  • 11
  • 2