You actually have your choice here when computing the cost of whether to use dot product style matrix multiplication or elementwise multiplication followed by a sum.
The key point in either strategy is to realize the shape of the input data. You can put in some print statements to check that both A and Y are row vectors with shape 1 x m, where m is the number of samples.
So you can compute A * Y elementwise for the first term there and follow that with np.sum to add up the products. The advantage of using the dot product is that it’s less code and more efficient at runtime because it computes the multiplication and the sum at once. But then the trick is that you can’t “dot” 1 x m with 1 x m, because the “inner” dimensions must match on a dot product. You need to transpose the second vector so that you are dotting 1 x m with m x 1, which gives you a 1 x 1 result (equivalent to a scalar).
This question has come up periodically over time. Here’s a thread that covers all this and has links to a number of other relevant threads if my quick explanation above isn’t sufficient.
Also note that you filed this under AI for Python, so I used the little “edit pencil” on the title to move it to DLS C1 W2.