1

I am doing an assignment on matrices and gradients, where the final answer must be expressed as a row vector.

vr = np.array([1, 2, 3])
vrr = np.array([[1, 2, 3]])

Mathematically, a row vector should be a 1×3 matrix, so the shape (1,3) seems to match that idea. However, NumPy treats (3,) as a 1D array, and many operations, like dot products and gradients, seem to work with this form as well.

What I want to clarify:

  1. Which of these is the true mathematical row vector?

  2. Which one should I use when a question explicitly asks for a row vector gradient?

  3. Is using shape (3,) mathematically ambiguous compared to (1,3)?

New contributor
Louis Chua is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

3
  1. Correct mathematical representation would be:
v = np.array([[1, 2, 3]]) # A (3,) NumPy array is not a matrix. It is a 1-dimensional object with no orientation at all.
  1. Go for shape(1,n): This is the only form that is unambiguously a row vector.

  2. Yes. The (3,) array has no row/column orientation. It can't be multiplied by matrices using true linear algebra rules unless NumPy broadcasts/coerces it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.