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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:52:03+00:00 2026-05-28T20:52:03+00:00

This thread in SO is about multidimensional array in c+ +. I have to

  • 0

This thread in SO is about multidimensional array in c++.

I have to port some code from c# to cpp. i have code like this:

private double[,] B;
...
this.B = new double[states, symbols];
double[][, ,] epsilon = new double[N][, ,]; 
double[][,] gamma = new double[N][,];
...
s += gamma[i][t, k] = ...

i have thought to use plain double array of array but it’s quite pain. another solution could be vector of vector of double, or a custom Matrix2D and Matrix3D classes?

what is the best way for each of those cases?



WHAT I LEARNED:

  • multidimensional array in c++ is a great topic, and internet is full of resources. it could be handled in various ways, some of them really tricky, some others more faster to write.

  • i think that the best way is to deal with it is to use some libraries that takes in account this topic. there are a lot of them: Armadillo (nice MATLAB syntax conversion), Eigen i think is one of the better one, easy to install, easy to use, powerfull. Boost::multi_array is anotherone, and Boost is really a famous lib that is important just to take a look at how it handle the topic. As Konrad Rudolph answer STD with nested vectors or this could be another solution but, after a little search, i think the less elegant even the more easy and fast to code without external libs.

  • write a custom class. mayebe such a good exercice. peter answer or this or this are a good start point and also this post is interesting but expecially this great post blog from martin moene (one of the best essay on this topic i’ve read today). I mention also this answer for sparse array.

  • here is a nice tutorial direct from stroustrup

  • have a nice time with multidimensional array 🙂

  • 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-28T20:52:04+00:00Added an answer on May 28, 2026 at 8:52 pm
    class StateSymbols
    {
    public:
        StateSymbols(unsigned int states, unsigned int symbols) :
        m_states(states),
        m_stateSymbols(states * symbols)
        {
        }
    
        double get(unsigned int state, unsigned int symbol) const
        {
            return m_stateSymbols[(m_states * symbol) + state];
        }
    
    private:
        const unsigned int m_states;
        std::vector<double> m_stateSymbols; 
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I go about this? I have 3 rows like so: ID THREAD
I found this thread about picking the closest/nearest value from an array based upon
In this thread some one commented that the following code should only be used
I found this thread on StackOverflow about how to get the Application Root from
I've found some information about xts fields representation in this thread but I'm still
I have this multidimensional array. I need to search it and return only the
Preface: This is not much about how to structure code within files. I have
So I invoke a thread from managed code this way: Action<EFScmTechnologiesContext, long, long> updateReference
I've taken a look at this thread about converting RTF to HTML but some
I came across this thread on SO which talks about PHP code coverage tools

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.