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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:11:05+00:00 2026-06-08T03:11:05+00:00

This is a beginner’s question but how do you save a 2d numpy array

  • 0

This is a beginner’s question but how do you save a 2d numpy array to a file in (compressed) R format using rpy2? To be clear, I want to save it in rpy2 and then later read it in using R. I would like to avoid csv as the amount of data will be large.

  • 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-08T03:11:07+00:00Added an answer on June 8, 2026 at 3:11 am

    Looks like you want the save command. I would use the pandas R interface and do something like the following.

    import numpy as np
    from rpy2.robjects import r
    import pandas.rpy.common as com
    from pandas import DataFrame
    a = np.array([range(5), range(5)])
    df = DataFrame(a)
    df = com.convert_to_r_dataframe(df)
    r.assign("foo", df)
    r("save(foo, file='here.gzip', compress=TRUE)")
    

    There may be a more elegant way, though. I’m open to better suggestions. The above, in R would be used:

    > load("here.gzip")
    > foo
      X0 X1 X2 X3 X4
    0  0  1  2  3  4
    1  0  1  2  3  4
    

    You can bypass the use of pandas and use numpy2ri from rpy2. With something like:

    from rpy2.robjects import r
    from rpy2.robjects.numpy2ri import numpy2ri
    a = np.array([[i*2147483647**2 for i in range(5)], range(5)], dtype="uint64")
    a = np.array(a, dtype="float64") # <- convert to double precision numeric since R doesn't have unsigned ints
    ro = numpy2ri(a)
    r.assign("bar", ro)
    r("save(bar, file='another.gzip', compress=TRUE)")
    

    In R then:

    > load("another.gzip")
    > bar
         [,1]         [,2]         [,3]         [,4]         [,5]
    [1,]    0 4.611686e+18 9.223372e+18 1.383506e+19 1.844674e+19
    [2,]    0 1.000000e+00 2.000000e+00 3.000000e+00 4.000000e+00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a beginner question, but it's been frustrating me... I am using C#,
This may be a beginner xml question, but how can I generate an xml
This is a beginner question with regard to using the SecureSocial(version 0.2.3 module with
This is a beginner's question but for some reason I cannot find the answer
i know this question was asked before but i have this very weird beginner
This is a beginner question, but please bear with me. I'd like to pass
I know this is a beginner's question, but I've been searching online and all
This is a beginner's question. I created a project called fileupload using pylons. I
I know this is a beginner question, but I've been banging my head against
This is a beginner question for java graphics using the awt package. I found

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.