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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:46:33+00:00 2026-05-31T10:46:33+00:00

If I have a Narray with the shape 100, 10000 and want to expand

  • 0

If I have a Narray with the shape 100, 10000 and want to expand it to say 100, 20000 (basically add rows) what is the proper way to achieve this? To expand massive Narrays I would like to avoid using a temporary Narray for memory reasons.

  • 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-05-31T10:46:34+00:00Added an answer on May 31, 2026 at 10:46 am
    require "narray"
    
    class NArray
      def expand(*new_shape)
        na = NArray.new(self.typecode,*new_shape)
        range = self.shape.map{|n| 0...n}
        na[*range] = self
        return na
      end
    end
    
    p a = NArray.float(2,3).indgen!
    # => NArray.float(2,3):
    #    [ [ 0.0, 1.0 ],
    #      [ 2.0, 3.0 ],
    #      [ 4.0, 5.0 ] ]
    
    p a.expand(3,4)
    # => NArray.float(3,4):
    #    [ [ 0.0, 1.0, 0.0 ],
    #      [ 2.0, 3.0, 0.0 ],
    #      [ 4.0, 5.0, 0.0 ],
    #      [ 0.0, 0.0, 0.0 ] ]
    

    There is no general way to expand a memory block without movement.
    Memory block can be extended only if enough free area follows,
    but such a case is usually unexpected.

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

Sidebar

Related Questions

I want to add a row to a two-dimensional NArray. The way described in
I have two NSArray objects and I want to add the two arrays together
I have NSArray and I want to remove duplicates from it. I know that
If I have an NSArray with some values in them. Is there a way
Example: I have an NSArray with 40 objects. What is the most efficient way
I am trying to add an image to the UIBarButtonItem which I have to
Suppose I have an immutable NSArray and want to create several sub-arrays. I could
I have a couple of view controllers that I want all to share a
I have an NSArray with several NSDictionaries . I want to create a new
I have an function that maps an ndarray of shape (3) to a float,

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.