Programming :: Multi Dimensional (3 Array) In Python
Jul 28, 2010
I do a lot of scientific work - mainly in C/C++ but want to do some of the calcs in python, however I am finding it a problem with the lack of dimensionality. I frequency have a list of n particles and a multi-dim array for each particle and want to be able to access directly any component with ease. How best to go about this...
my prop = [n][x][y][z]
I might need a particular value and then to update that. I do not want to have to deal with lists etc etc as this feels rather cumbersome, adding, removing etc. There must be an easy way.
I need to sort it by array[ $key ][ 2 ] so that it is sorted like so: Code: Array ( [0] => Array ( [0] => Eleven [1] => NumberEleven [2] => 11 ) [1] => Array ( [0] => AnotherEleven [1] => Eleven,Again [2] => 11 ) [2] => Array ( [0] => Twelve [1] => NumberTwelve [2] => 12 )
I've looked at the php array docs the closet thing I found was array_multisort which won't work for my above requirements, does anyone have any insight to how to sort this way?
I am parsing through XML documents with a PHP script and creating an array because, as far as I know, I can manipulate arrays better than the features DOM gives me. That part is not as important, though. The array it produces though is multi-dimensional, but somewhat inconsistent. If I have the following XML:
To call the first bookmark from the first domain, it would be: PHP Code: $array['domains']['domain'][0]['bookmarks']['bookmark'][0] To call the first bookmark from the second domain, it would be: PHP Code: $array['domains']['domain'][1]['bookmarks']['bookmark']
The problem is, I want to simply call bookmarks through a simply 'foreach()' or 'for()' function and the lack of consistency might be a problem, but the fact that some levels have a '0' array key and others do not is causing a problem.
I have never used multidimensional array for a long time so please consider this as a newbie question. I am editing a program that uses a 4 dimensional array and I think I'm losing track of the indexes.
day = 0 to 30 hour = 0 to 23 channel = 0 to 7 len = 0 to 63 unsigned char idx[day][channel][hour][len];
I have seen that the assignment to a string is snprintf(idx[day][hour][channel], 64, "%s/%s", dayofmonth, hourofday); Is this correct? Because when I access with a day argument, that day value goes into the hour part.
I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').
The problem is that by the default the sort is case-sensitive so the array looks like this: Code: Apple 4015 Banana 4011 Cherry 4045 avocado 4046
I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like: Code: Apple 4015 avocado 4046 Banana 4011 Cherry 4045
How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.
I am curious if there is a way to describe and use variable sized multi-dimensional arrays in C using pointers. I mean, for 1-dimensional array e.g. I can use the following piece of code:
... int i , N; int *array; scanf("%d", &N); array = (int*) malloc(N*sizeof(int)); for (i=0; i<N; ++i) array[i] = i; // Assigning values to the array for (i=0; i<N; ++i) printf("%d ", array[i]); // Printing the assigned values free (array); ...
But what about the two dimensional array[N][M] ? I guess I have to use a double pointer e.g: int **array. But how exactly? Note that I use C90 and not C99.
I tried to look for this, but there are so little of perl on internet: Code: @array = [$title, $description, $pubDate, $link]; push(@feeds1, $array);
I am trying to create a 2 D array by PUSH, so the output would look like: ([ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ]...etc )
I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.
(I am using vector() and matrix() functions from "Numerical recipes in C".)There are 100 numbers to be stored in 2D array of 10 rows and 10 columns.100 numbers are stored in a 1D array.I get "segmentation fault" at the line indicated in the segment of my code below:
I have a function definition in a Python 2.x script which take a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash addelementtoarray() { local arrayname=$1
I want that I click with the mouse on the video, it paused.I notice that there is "BaconVideoWidget" which I guess is the video rendering widget but it don't have signal named "clicked":
I ran into an inconsistency in handling timers (VTALRM) between AMD and intel platforms with threads. My understanding was that the timers are per process. I discovered I must call setitimer in the thread on intel though. AMD allows me to make the setitimer call once in the main thread as expected. The code below demonstrates the issue. I must add the code in the INTEL define for it to work properly on intel cpu's. Am I missing something dumb??
So I have built a program that takes a picture from two cameras every second and converts them both to jpeg format. The problem is that currently it takes ~2 seconds to convert a single raw photo to jpeg format, thus every second I add another raw photo (30 MB) to ram waiting to be converted to jpeg. So, theoretically the conversion to jpeg is running on a single core with hyperthreading, would I see better performance running the exact same process (a program pulling from a queue and converting to jpeg) running as a single process, or two concurrent processes? (both processes running on the same core, (so 1 thread on one clock cycle, the other on the other... (or one thread running on 1 core and the other on another core. What other steps would you take to improve the performance so there would no longer be a race condition?
I have an ATI Radeon HD 3300 on-board video chipset, and an ATI Radeon HD 4350 PCI card. What I want is to have both displays available from one mouse/keyboard. I want to play media on one and have the other as my main desktop.The problem is that with Xinerama enabled, KDE desktop effects do not work (KDE says XComposite and XDamage are not available, even though I explicitly enabled them as extensions in the xorg.conf file), and performance is quite bad. Without Xinerama enabled, performance is great, desktop effects work great, but there's a lot of trouble with full-screen video, and the KWin window manager does not apply in the second display (although I can run a second instance of KWin on :0.1).
I have a 2GB file which is a dd image of a block device. The block device (a USB-connected flash memory) contains multiple partitions, and therein lies the problem. I want/need to access the various partitions in the image file, but need to do this without actually using a physical flash memory device. If the image was that of a single partition, I could simply mount it on a loop device, and access the filesystem as necessary. However, I can find no kind of virtual block device upon which to write/mount the image.
I've searched the net exhaustively for anything that would seem to allow me to do what I need, but without even a sniff of success. Sadly, I have seen bits of information that suggest "you can't get there from here". Even the outstanding dd tutorial by AwesomeMachine on LQ didn't help. Anyone know of a kind of virtual block device on which a multi-partition image can be written and mounted? Or any other way I can access individual partitions (with various filesystem types on each) and then re-assemble them back to a single image?
I would like to have a script that will do a search in an XML file for a specific block of XML code and replace it with a different block of XML code using the Windows build of GNU Sed 4.1.5.
Here's the text I want to find:
Code:
And here's what I want to replace it with:
Code:
There is however a lot of stuff in there that would mess up sed, and the one example from the sed FAQ (from the Sourceforge site) that looked promising and easy enough to figure out (4.23.3. Try to use a block of "literal strings") fails with this error message: sed: file blockrep.sed line 18: unterminated `s' command
Anyone got any ideas, or even an alternate program that can do this? (Preferably one that I can automate.)
i got basic knowledge about creating a single child from a parent using fork(). But when it comes into creating multiple children, i am simply stuck. I am trying to create two processes from a parent and it would wait for both two processes to finish. my attempt is as below
Anyone successfully using VNC client on a Mac to control a Debian server?I have the vncserver setup on the Debian machine properly. But I'm having problems connecting to it from both a PowerMac running Tiger and a MacBookPro running leopard.I can connect no problem from a machine running Slack12.2, have not setup port forwarding on my router to connect remotely yet.My Debian machine is running the latest stable release of squeeze with KDE4.I originally tried this with RealVNC Enterprise for OSX but I'm not gonna buy it so I need another alternative after the 30 day trial ends as they have no free version for OSX. The situation is that I do freelance graphic design on the PowerMac with Cinema4D and Photoshop so I spend most of my time on that machine which is located in my home studio in my attic. Aside from the MacBook and a Dell desktop(family machine)all my other machines and network hardware are in the basement. So to go from the attic to the basement everytime I need to do something on another machine is not practical, and the only other machine I need to access on a regular basis is the Debian box in the basement, this makes the most sense.
I also have a 14 year old living in the house and he's fascinated by all this and will meddle in anything he gets the chance to so all the Linux machines and network hardware need to be behind lock and key.
This array is supposed to contain 12 elements (names of the month) What I want to achieve is that depending on some user input (a number 1-12) a full name of one of the months will be displayed, eg.
Code: scanf("%d", &month); printf("The month is %c", months_names[month]);