# Dimensions For Matrix Multiplication

Can anyone explain why the following code produces input_t with a shape of (32,) instead of (,32), given the fact that inputs has a shape (100, 32)? Shouldn't input_t produce a vector with 32 attributes/columns?

import numpy as np

timesteps = 100
input_features = 32
output_features = 64

inputs = np.random.random((timesteps, input_features))

state_t = np.zeros((output_features,))

W = np.random.random((output_features, input_features))
U = np.random.random((output_features, output_features))
b = np.random.random((output_features,))

successive_outputs = [ ]

for input_t in inputs:
output_t = np.tanh(np.dot(W, input_t) + np.dot(U, state_t) + b)
successive_outputs.append(output_t)
state_t = output_t

• What is U parameters for? Is this supposed to be a neural network? Commented May 30, 2018 at 16:01
• Yes, it's a simple naive implementation of RNN found here Commented May 30, 2018 at 16:16

Imagine the matrix inputs as a 2D table. You have 100 rows and 32 columns. Then the for loop acts as an iterator which will return values along the first dimensional axis. This dimension thus disappears and returns the remaining dimensions. When there is a single dimension the default in Python is $(n,)$.
A matrix $(100, 32)$ iterates through $(32,)$
A matrix $(100,28,28)$ iterated through $(28,28)$
A matrix $(100,2,2,2)$ iterated through $(2,2,2)$
• It makes sense. For insight, I was ultimately evaluating how the matrices W and input_t posses the correct dimensions for multiplication in np.dot(W, input_t). Thanks for the insight! Commented May 30, 2018 at 16:34