Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9068285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:09:19+00:00 2026-06-16T17:09:19+00:00

Is there a standard practice for representing vectors as 1d or 2d ndarrays in

  • 0

Is there a standard practice for representing vectors as 1d or 2d ndarrays in NumPy? I’m moving from MATLAB which represents vectors as 2d arrays.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:09:20+00:00Added an answer on June 16, 2026 at 5:09 pm

    In my experience, 1D is the norm in numpy for vectors. The only good reason to keep a vector of n elements as a 2D array of shape (1, n) or (n, 1) is in a linear algebra context, where you wanted to keep row and column vectors differentiated. As EitanT hinted on his now deleted answer, you would probably then want to use numpy’s matrix type, which keeps 2D shape of returns except for single element access, e.g if a has shape (m, n) then a[0] has shape (n,) for type ndarray, but shape (1, n) for type matrix, although a[0, 0] returns a scalar in both cases.

    If you stick with 1D vector of shape (n,), you can reshape on the fly for specific operations requiring the 2D shape:

    a.reshape(-1, 1) # shape (n, 1)
    a[:, None] # shape (n, 1)
    a.reshape(1, -1) # shape (1, n)
    a[None, :] # shape (1, n)
    

    Numpy will automatically reshape your 1D vectors to shape (1, n) when broadcasting it for an operation with a 2D array involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a standard practice to organize the process of developing a simple website.
I was wondering if there is a standard practice regarding the use of labels
is there a standard or best practice with database table names and fields in
Is there a standard Java library that handles common file operations such as moving/copying
Is there a standard way of maintaining a weak pointer to a parent (which
Are there any standard or best practice ways of limiting feature functionality for a
Is there any standard practice to DRY-out the repeating unit test cases in rails.
I was wondering if there is any standard practice in using components in Haxe.
Is there a standard or best practice for the order of grouping of styles
I forked a project on Github from source A. Since then, the standard practice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.