473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Converting a 4D array to a 1D array and addressing it

I have a four dimensional array which I am trying to flatten into a single
dimension array:

Dim Array4D(10,10,10,10) as Single

I can create my one dimensional array to be big enough to contain teh data
from the 4D array:

Dim Array2D(Array4D.Length - 1) As Single

Then I populate it like so:

Dim intArray2dIndex As Integer
For t As Integer = 0 To Array4D.GetUpperBound(0)
For x As Integer = 0 To Array4D.GetUpperBound(1)
For y As Integer = 0 To Array4D.GetUpperBound(2)
For z As Integer = 0 To Array4D.GetUpperBound(3)
Array2D(intArray2dIndex) = Array4D(t, x, y, z)
intArray2dIndex += 1
Next
Next
Next
Next

But once I have my 1D array how do I retrieve a value from it using the
original t,x,y,z values? In other words, given a t, x, z and y value that
would describe a position in the 4D array I need to translate that to a
single value that describes the position in the one dimensional array.

Any help on this one?

TIA
Nov 21 '05 #1
4 4340
Just out of interest, if you are trying to represent homogenous coordinates,
why not create a single Vertex class and have an array of Vertices?

public class Vertex

public x, y, z, t as single

end class

Dim myArray(1) as Vertex

for each theVertex as Vertex in myArray
theVertex.x = 10.0
next
"elziko" <el****@yahoo.co.uk> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
I have a four dimensional array which I am trying to flatten into a single
dimension array:

Dim Array4D(10,10,10,10) as Single

I can create my one dimensional array to be big enough to contain teh data
from the 4D array:

Dim Array2D(Array4D.Length - 1) As Single

Then I populate it like so:

Dim intArray2dIndex As Integer
For t As Integer = 0 To Array4D.GetUpperBound(0)
For x As Integer = 0 To Array4D.GetUpperBound(1)
For y As Integer = 0 To Array4D.GetUpperBound(2)
For z As Integer = 0 To Array4D.GetUpperBound(3)
Array2D(intArray2dIndex) = Array4D(t, x, y, z)
intArray2dIndex += 1
Next
Next
Next
Next

But once I have my 1D array how do I retrieve a value from it using the
original t,x,y,z values? In other words, given a t, x, z and y value that
would describe a position in the 4D array I need to translate that to a
single value that describes the position in the one dimensional array.

Any help on this one?

TIA

Nov 21 '05 #2
On Fri, 24 Jun 2005 15:52:47 +0100, "elziko" <el****@yahoo.co.uk>
wrote:
I have a four dimensional array which I am trying to flatten into a single
dimension array:

Dim Array4D(10,10,10,10) as Single

I can create my one dimensional array to be big enough to contain teh data
from the 4D array:

Dim Array2D(Array4D.Length - 1) As Single

Then I populate it like so:

Dim intArray2dIndex As Integer
For t As Integer = 0 To Array4D.GetUpperBound(0)
For x As Integer = 0 To Array4D.GetUpperBound(1)
For y As Integer = 0 To Array4D.GetUpperBound(2)
For z As Integer = 0 To Array4D.GetUpperBound(3)
Array2D(intArray2dIndex) = Array4D(t, x, y, z)
intArray2dIndex += 1
Next
Next
Next
Next

But once I have my 1D array how do I retrieve a value from it using the
original t,x,y,z values? In other words, given a t, x, z and y value that
would describe a position in the 4D array I need to translate that to a
single value that describes the position in the one dimensional array.

Any help on this one?

TIA


First work out out on paper how you would flatten a 2D array into a 1D
array, and how you would retrieve the array entries given the two
indices. Program your solution and test it.

Next do the same for flattening a 3D array. Test your solution so you
are sure that it works.

After doing that you should be in a position to solve your problem
with a 4D array.

rossum

The ultimate truth is that there is no ultimate truth
Nov 21 '05 #3
A simplified piece of code would be:

offset1 = Array4D.GetUpperBound(1) * Array4D.GetUpperBound(2) * _
Array4D.GetUpperBound(3)
offset2 = Array4D.GetUpperBound(2) * Array4D.GetUpperBound(3)
offset3 = Array4D.GetUpperBound(3)

Each element would be at

value = Array2D((t*offset1) + (x*offset2) +(y*offset3) + z)

Cheers,
Jason

On Fri, 24 Jun 2005 15:52:47 +0100, elziko wrote:
I have a four dimensional array which I am trying to flatten into a single
dimension array:

Dim Array4D(10,10,10,10) as Single

I can create my one dimensional array to be big enough to contain teh data
from the 4D array:

Dim Array2D(Array4D.Length - 1) As Single

Then I populate it like so:

Dim intArray2dIndex As Integer
For t As Integer = 0 To Array4D.GetUpperBound(0)
For x As Integer = 0 To Array4D.GetUpperBound(1)
For y As Integer = 0 To Array4D.GetUpperBound(2)
For z As Integer = 0 To Array4D.GetUpperBound(3)
Array2D(intArray2dIndex) = Array4D(t, x, y, z)
intArray2dIndex += 1
Next
Next
Next
Next

But once I have my 1D array how do I retrieve a value from it using the
original t,x,y,z values? In other words, given a t, x, z and y value that
would describe a position in the 4D array I need to translate that to a
single value that describes the position in the one dimensional array.

Any help on this one?

TIA

Nov 21 '05 #4
> Just out of interest, if you are trying to represent homogenous
coordinates, why not create a single Vertex class and have an array of
Vertices?


I cannot do this because I am writing to a propriety file format using a 3rd
party DLL requiring me to start with a 1D array of singles.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
4
by: elziko | last post by:
I have a four dimensional array which I am trying to flatten into a single dimension array: Dim Array4D(10,10,10,10) as Single I can create my one dimensional array to be big enough to contain...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
33
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
0
by: lvpaul | last post by:
Hello ! I am calling a .NET Webservice and getting back a ADO.NET Datatset. How can I convert this to an PHP-Array ? $ergebnis = $m_service->call( $function, $data ); print_r($ergebnis)...
23
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing...
2
by: Je-Givara | last post by:
i read in some books that the array address in Unique Could any one explain me and show that array addressing is unique. Thanks for advance!
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
2
by: Miles | last post by:
Hi all, Wondering if anyone can help me. If i have an associative array: $arr = array( "one" =array(1, 2, 3), "two" =array(5, 6), "three" =array(7,8,9,10) .... "n" =array(p,q,r....)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.