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

  • Home
  • SEARCH
  • 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 9179499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:48:44+00:00 2026-06-17T17:48:44+00:00

I read the following in the numpy documentation for the function r_ : A

  • 0

I read the following in the numpy documentation for the function r_:

A string integer specifies which axis to stack multiple comma
separated arrays along. A string of two comma-separated integers
allows indication of the minimum number of dimensions to force each
entry into as the second integer (the axis to concatenate along is
still the first integer).

and they give this example:

>>> np.r_['0,2', [1,2,3], [4,5,6]] # concatenate along first axis, dim>=2
array([[1, 2, 3],
       [4, 5, 6]])

I don’t follow, what does exactly the string '0,2' instruct numpy to do?

Other than the link above, is there another site with more documentation about this function?

  • 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-17T17:48:45+00:00Added an answer on June 17, 2026 at 5:48 pm

    'n,m' tells r_ to concatenate along axis=n, and produce a shape with at least m dimensions:

    In [28]: np.r_['0,2', [1,2,3], [4,5,6]]
    Out[28]: 
    array([[1, 2, 3],
           [4, 5, 6]])
    

    So we are concatenating along axis=0, and we would normally therefore expect the result to have shape (6,), but since m=2, we are telling r_ that the shape must be at least 2-dimensional. So instead we get shape (2,3):

    In [32]: np.r_['0,2', [1,2,3,], [4,5,6]].shape
    Out[32]: (2, 3)
    

    Look at what happens when we increase m:

    In [36]: np.r_['0,3', [1,2,3,], [4,5,6]].shape
    Out[36]: (2, 1, 3)    # <- 3 dimensions
    
    In [37]: np.r_['0,4', [1,2,3,], [4,5,6]].shape
    Out[37]: (2, 1, 1, 3) # <- 4 dimensions
    

    Anything you can do with r_ can also be done with one of the more readable array-building functions such as np.concatenate, np.row_stack, np.column_stack, np.hstack, np.vstack or np.dstack, though it may also require a call to reshape.

    Even with the call to reshape, those other functions may even be faster:

    In [38]: %timeit np.r_['0,4', [1,2,3,], [4,5,6]]
    10000 loops, best of 3: 38 us per loop
    In [43]: %timeit np.concatenate(([1,2,3,], [4,5,6])).reshape(2,1,1,3)
    100000 loops, best of 3: 10.2 us per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following: you read in a string with scanf() but you only need
how do I read the following xml document? My code is : var vb
I recently read the following overflow post: Hidden Features of C# One of the
I've read the following post. My Code looks exactly the same, but does not
I am trying to read the following xml stream but am really struggling. <channelSnapshot
I'm trying to read the following Xml document as fast as I can and
So I have the following read and write file program for an Array. How
First of all let me tell you that i have read the following questions
I need to write a simple program for work that does the following: read
I recently read the the following SO question. What's the best way to store

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.