1

I want to slice a column, but this gives me a one dimensional array. i.e.

import numpy as np

a = np.arange(9).reshape(3,3)
b = a[1,:]


b.shape
# (3,)

But I want it to be 2 dimensional, i.e. (3,1)

Is there a way to do this without reshaping?

liyuan
  • 543
  • 3
  • 16
  • So in your case, `a[1, :, np.newaxis]`. – miradulo Apr 17 '18 at 00:15
  • Why do you want it to be (3,1)? Wouldn't (1,3) make more sense when selecting a row? like `a[[1],:]`. Reshaping gives you more control without costing anything but a bit of typing. – hpaulj Apr 17 '18 at 00:28

0 Answers0