- #1
madsmh
- 32
- 2
I'm am looking for a C++ library that supports high-dimensional arrays ( 3=< ) and element-wise calculations.
Is there such a thing?
Is there such a thing?
int fourDArray[10][10][10][10];
newjerseyrunner said:What exactly are you trying to do? Native C++ supports as many dimensions as you want:
Code:int fourDArray[10][10][10][10];
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.madsmh said: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.
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++.madsmh said:Perhaps I wasn't clear. What I'm looking for is a numpy-like library for C++.
Mark44 said: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++.
As an example, here's some code that creates essentially a 4 x 4 matrix of column vectors, with each column vector beingjim mcnamara said:Okay - the answer is the standard C++ (or C) library handles multidimensional arrays.
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;
}
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)
A multidimensional array is a data structure that allows you to store data in multiple dimensions, such as rows and columns. It is often used to represent data that is organized in a table-like format.
A library that supports multidimensional arrays can provide you with tools and functions to efficiently work with and manipulate this type of data structure. This can save you time and effort when working with large amounts of data.
Some features to consider when looking for a library that supports multidimensional arrays include the ability to create, access, and modify arrays of different dimensions, as well as functions for performing common operations on arrays, such as sorting and searching.
Yes, many libraries that support multidimensional arrays have the ability to store different data types within the same array. This can be useful when working with heterogeneous data sets.
Yes, there are many popular libraries that support multidimensional arrays, such as NumPy, SciPy, and Pandas in Python, and Java's Multidimensional Array class. It is important to research and choose a library that best fits your specific needs and programming language.