Skip to content

Why does the error message ask me to use * instead of @? #3

Closed Answered by TheKidPadra
zahrafarajih asked this question in Q&A
Discussion options

You must be logged in to vote

I believe something is fishy with using b@b.T. 1D arrays in Numpy do not always behave like vectors.

Try and check what the result for b@b.T is. One piece of advice I would give when you debug errors like this is to break the long expression into smaller parts. For example, you have "P = np.eye(D) @ ((b @ b.T) / (b @ b))". This error you have occurred because one of the operand of your @ operator is a scalar. But which one is it?

import numpy as np
b = np.ones(3)
D, = b.shape

# instaed of doing P = np.eye(D) @ ((b @ b.T) / (b @ b)), break it down.

numer = b @ b.T
denom = (b @ b)

# Check out the shape of numer and denom to see why this fails.
print(numer.shape)
print(denom.shape)
P = np…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zahrafarajih
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed question Further information is requested
2 participants