# My_dense function

hi
here is the code for my_dense function in C2_W1_Lab03_CoffeeRoasting_Numpy

def my_dense(a_in, W, b):
“”"
Computes dense layer
Args:
a_in (ndarray (n, )) : Data, 1 example
W (ndarray (n,j)) : Weight matrix, n features per unit, j units
b (ndarray (j, )) : bias vector, j units
Returns
a_out (ndarray (j,)) : j units|
“”"
units = W.shape[1]
a_out = np.zeros(units)
for j in range(units):
w = W[:,j]
z = np.dot(w, a_in) + b[j]
a_out[j] = g(z)
return(a_out)

in the lab, W is a (2,3) matrix so units = W.shape[1] makes sure units represent the number of features which is three.
but why does it use 1? wouldnt 0 be more suitable? because in another scenaria, W could well be a (1,3) matrix then W.shape[1] wouldnt exist.

what do you think the problem is with my logic?

Mehmet

ndarray.shape returns a tuple representing the dimensions of the array. Tuples are 0 indexed. So grabbing the second item out of that tuple will give you the number 3. A 1,3 matrix would still return a 3 as the second value in the shape.

1 Like