0

I have been using python for a few months now and cant figure out why the following doesn't work. I searched around stack.

How to reproduce my problem

import numpy as np
K = np.zeros((48,48))
colloc = np.arange(12)
print(K[colloc,colloc])

I would expect a matrix of 12 by 12. It gives me a vector of 12,1.

So I tried the below and all of them worked, except when I used [colloc,colloc], which is when I get a vector of dimension 12.

print(K[1:3,1:3])
print(K[colloc,1:3])
print(K[1:3,colloc])
print(K[:12,colloc])

I cant figure out what is happening... The error seems to come because of np.arange statement. I will appreciate your help! Thank you. I have tested this inside ipython notebook, while running a python file and in the 'ipdb' mode. All give same results.

agent18
  • 2,109
  • 4
  • 20
  • 34

0 Answers0