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 9301923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:08:22+00:00 2026-06-18T23:08:22+00:00

How do I stack column-wise n vectors of shape (x,) where x could be

  • 0

How do I stack column-wise n vectors of shape (x,) where x could be any number?

For example,

from numpy import *
a = ones((3,))
b = ones((2,))

c = vstack((a,b)) # <-- gives an error
c = vstack((a[:,newaxis],b[:,newaxis])) #<-- also gives an error

hstack works fine but concatenates along the wrong dimension.

  • 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-18T23:08:23+00:00Added an answer on June 18, 2026 at 11:08 pm

    Short answer: you can’t. NumPy does not support jagged arrays natively.

    Long answer:

    >>> a = ones((3,))
    >>> b = ones((2,))
    >>> c = array([a, b])
    >>> c
    array([[ 1.  1.  1.], [ 1.  1.]], dtype=object)
    

    gives an array that may or may not behave as you expect. E.g. it doesn’t support basic methods like sum or reshape, and you should treat this much as you’d treat the ordinary Python list [a, b] (iterate over it to perform operations instead of using vectorized idioms).

    Several possible workarounds exist; the easiest is to coerce a and b to a common length, perhaps using masked arrays or NaN to signal that some indices are invalid in some rows. E.g. here’s b as a masked array:

    >>> ma.array(np.resize(b, a.shape[0]), mask=[False, False, True])
    masked_array(data = [1.0 1.0 --],
                 mask = [False False  True],
           fill_value = 1e+20)
    

    This can be stacked with a as follows:

    >>> ma.vstack([a, ma.array(np.resize(b, a.shape[0]), mask=[False, False, True])])
    masked_array(data =
     [[1.0 1.0 1.0]
     [1.0 1.0 --]],
                 mask =
     [[False False False]
     [False False  True]],
           fill_value = 1e+20)
    

    (For some purposes, scipy.sparse may also be interesting.)

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

Sidebar

Related Questions

SELECT count(*) FROM Stack WHERE Id = 33478 GROUP BY SID Output: (No column
I have a column dek with the following data I like Stack Overflow site.
Dear SQL Gurus from Stack Overflow: Environment: Oracle I'm trying to understand why I
I'm relatively new to Python and wondering how best to import data from multiple
This is a repost from the Statistics portion of the Stack Exchange. I had
Dear Stack Overflow community, I am using PostgreSQL databases from C# with the NpgSql
I want to use stack to a data frame and keep duplicate columnnames from
Someone (w69rdy) in Stack Overflow helped me out with a great example to handle
Does anyone know how to make jQuery masonry stack from the bottom up? I
I need to do something like this: https://i.stack.imgur.com/97zZM.jpg with the first black column always

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.