I have a matrix that I initialized with
W = np.random.uniform(-1, 1, (V,N))
V = 10000
N = 50
They are different operations. matrix (in the maths sense) times matrix gives matrix, some of your matrices just happen to have width 1.
Indexing with an integer scalar eats the dimension you are indexing into. Once you are down to a single dimension,
.T does nothing because it doesn't have enough axes to shuffle.
If you want to go from (50,) to (50, 1) shape-wise, the recipe is indexing with
None like so
v[:, None]. In your case you have at least two one-line options:
W[x, :][:, None] # or W[x][:, None] or W[x:x+1, :].T # or W[x:x+1].T
The second-line option preserves the first dimension of
W by requesting a subrange of length one. The first option can be contracted into a single indexing operation - thanks to @hpaulj for pointing this out - which gives the arguably most readable option:
W[x, :, None]
The first index (scalar integer
x) consumes the first dimension of
W, the second dimension (unaffected by
:) becomes the first and
None creates a new dimension on the right.