I have a numpy array which has 100 rows and 16026 columns. I have to find the median of every column. So median for every column will be calculated from 100 observations (100 rows in this case). I am using the following code to achieve this:

```
for category in categories:
    indices = np.random.randint(0, len(os.listdir(filepath + category)) - 1, 100)
    tempArray = X_train[indices, ]
    medArray = np.median(tempArray, axis=0)
    print(medArray.shape)

```

And here's the output that I get:

```
(100, 16026)
(100, 16026)
(100, 16026)
(100, 16026)

```

My question is - why is the shape of `medArray` 100\*16026 and not 1\*16026? Because I am calculating the median of every column, I would expect only one row with 16026 columns. What am I missing here? 

Please note that `X_train` is a sparse matrix.

```
X_train.shape

```

output:

```
(2034, 16026)

```

Any help in this regard is much appreciated.

**Edit:**

The above problem has been solved by `toarray()` function.

```
tempArray = X_train[indices, ].toarray()

```

**I also figured that I was being stupid and also including all the zeroes in my median calculation and that's why I was getting 0 as the median all the time. Is there an easy way of calculating the median by removing/ignoring the zeroes across all the columns?**