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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:16:44+00:00 2026-06-11T20:16:44+00:00

I am trying to map a 1D array onto 3D array using provided list

  • 0

I am trying to map a 1D array onto 3D array using provided list of dimensions.

Here are my components:

SEXP data; // my 1D array
// I can initialise new 3D vector in the following way:
NumericVector vector(Dimension(2, 2, 2);
// or the following:
NumericVector vector(data.begin(), data.end());

What I didn’t figure out is how can I create a NumericVector that would have both my data and the desired dimensions.

  • 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-11T20:16:45+00:00Added an answer on June 11, 2026 at 8:16 pm

    It is doable, but a little painful. I guess a decent (and tested) contribution for new constructor or helper function would be appreciated.

    In the meantime, you can do what the example below does. But be careful about row-major and col-major etc. Another option is RcppArmadillo which has a proper ‘Cube’ type generalizing matrices to 3-d.

    R> library(inline)
    R> fx <- cxxfunction(signature(vs="numeric", ds="integer"), plugin="Rcpp", body='
    +    Rcpp::NumericVector v(vs);            // get the data
    +    Rcpp::Dimension d(ds);                // get the dim object
    +    Rcpp::NumericVector r(d);             // create vec. with correct dims
    +    std::copy(v.begin(), v.end(), r.begin());  // and copy
    +    return Rcpp::List::create(v, d, r);
    + ')
    R> fx(1:8, c(2,2,2))
    [[1]]
    [1] 1 2 3 4 5 6 7 8
    
    [[2]]
    [1] 2 2 2
    
    [[3]]
    , , 1
    
         [,1] [,2]
    [1,]    1    3
    [2,]    2    4
    
    , , 2
    
         [,1] [,2]
    [1,]    5    7
    [2,]    6    8
    
    
    R>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display an array of postcodes onto a google map using PHP
Trying to map the following schema using the Entity Framework. A Customer can have
I'm trying to map a list of fields from a website using php DOMXPath
Here ,I am trying to convert map values into String array but i am
I am trying to create a map using two arrays. Here is the code:
I have an array of Deferred objects, which I'm trying to map to their
I am trying to map a legacy database here and I'm running into a
I'm trying to map an array into an ICollection of type <T>. Basically I
I'm trying to map some data (returned from a jQuery $.ajax call) to a
I'm trying to create map (using the Google Maps JavaScript API V3 ) which

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.