- #1

- 31

- 2

Is there such a thing?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter madsmh
- Start date

- #1

- 31

- 2

Is there such a thing?

- #2

- 1,533

- 633

Code:

`int fourDArray[10][10][10][10];`

- #3

- 31

- 2

Code:`int fourDArray[10][10][10][10];`

I have N x N 1x3 vectors that I need to be able to sum element-wise row-wise. I also need to do element-wise calculations on N x 3 arrays.

- #4

Mentor

- 37,031

- 9,125

This could be implemented as a three-dimensional array, something that is straightforward enough that I doubt that there is a library of the type you're looking for. With regard to "sum element-wise row-wise," you need to be a bit more explicit as to what you mean.I have N x N 1x3 vectors that I need to be able to sum element-wise row-wise.

Nearly all C++ textbooks have a section on working with multidimension arrays. I'm sure there are also many online tutorials about the same subject.madsmh said:I also need to do element-wise calculations on N x 3 arrays.

- #5

- 31

- 2

Perhaps I wasn't clear. What I'm looking for is a numpy-like library for C++.

- #6

Mentor

- 37,031

- 9,125

No, you were clear. What @newjerseyrunner and I are saying is that no such library is needed. Even if such a library existed, the time it would take to learn how to use that API would be at least as much as the time it takes to learn how to use multidimension arrays in C++.Perhaps I wasn't clear. What I'm looking for is a numpy-like library for C++.

- #7

- 31

- 2

No, you were clear. What @newjerseyrunner and I are saying is that no such library is needed. Even if such a library existed, the time it would take to learn how to use that API would be at least as much as the time it takes to learn how to use multidimension arrays in C++.

And that, like Mark44's post, does not answer my question.

- #8

Mentor

- 4,715

- 3,678

Lapack handles multidimensional tensors (matrices)- Linear algebra. More good add-ons.

http://www.boost.org/

http://www.netlib.org/lapack/

These extend the base standard library. This is as close to an answer for the question as posed. I believe:

Please tell us what you are trying to do. Please do not ask a question assuming you know how to accomplish the task, in this case some library you think must exist.

- #9

Mentor

- 37,031

- 9,125

As an example, here's some code that creates essentially a 4 x 4 matrix of column vectors, with each column vector beingOkay - the answer is the standard C++ (or C) library handles multidimensional arrays.

##\begin {bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}##

The following code creates a 3D array, one "slice" of which looks like this:

##\begin{bmatrix} 1 & 1 & 1 & 1 \\

2 & 2 & 2 & 2 \\

3 & 3 & 3 & 3 \end{bmatrix}##

The other "slices" look the same

C:

```
int main()
{
int vectors[4][3][4];
int i, j, k;
for (k = 0; k < 4; k++) // Each column
{
for (j = 0; j < 3; j++) // Each row
{
for (i = 0; i < 4; i++) // Each slice
vectors[i][j][k] = 1 + j;
}
}
return 0;
}
```

- #10

- #11

Homework Helper

- 8,808

- 590

- #12

- 31

- 2

The project I am working on is N-Body simulator for predicting Solar System orbits in Python, and I would like to speed

up the computations without loosing the graphical abilies of Python. As an example of what I would like to to do in C++ is the Verlet integrator which I have implemented like this:

Python:

```
def verlet(system, trajectory, rows, delta_t):
delta_t2 = delta_t ** 2
# TODO Implement Velocity Verlet
for k in range(rows):
if k == 0:
# Get initial positions
q0 = system.get_positions()
# Save to trajectory
trajectory.set_trajectory_position(q0)
elif k == 1:
# Get previous position
q0 = trajectory.get_position_at_index(0)
# Get initial velocity
p0 = system.get_velocities()
# Calculate accerleration
a = system.get_accelerations()
# Calculate q1
q1 = q0 + p0 * delta_t + 0.5 * a * delta_t2
# Save to trajectory
trajectory.set_trajectory_position(q1)
# Update positions of the planets
system.set_positions(q1)
# Calculate q_n+1
else:
# Calculate accerleration
a = system.get_accelerations()
# Get the prevous results
qn1 = trajectory.get_position_at_index(k-2)
qn = trajectory.get_position_at_index(k-1)
# Calculate new new positions
qplus = 2*qn - qn1 + a * delta_t2
# Save to trajectory
trajectory.set_trajectory_position(qplus)
# Update positions of the planets
system.set_positions(qplus)
```

As you can see I am able to do computations with multiple N x 3 arrays in a single line of code with Numpy.

I was hoping that there would be a similar facillities in C++ via a library.

Share:

- Replies
- 4

- Views
- 828

- Replies
- 4

- Views
- 690

- Replies
- 3

- Views
- 1K

- Replies
- 15

- Views
- 2K

- Replies
- 2

- Views
- 893

- Replies
- 33

- Views
- 589

- Replies
- 4

- Views
- 511

- Replies
- 2

- Views
- 86

- Replies
- 8

- Views
- 523

- Replies
- 5

- Views
- 712