array-manipulation

Grouping arrays in PHP

I have an array of 200 items. I would like to output the array but group the items with a common value. Similar to SQL's GROUP BY method. This should be relatively easy to do but I also need a count for the group items. Does anyone have an efficient way of doing this? This will happen on every page load so I need it to be fast and scala...

How can I print only every third index in Perl or Python?

How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array. ...

How to get x and y coordinates from a linear grid simply?

I have myself a linear grid of Vector2s stored in a Vector2[,] array, and i also have another Vector2 that lies within this grid. How can i simply extract both the nearest 4 grid points and their indexes in the array? I'm totally stumped... ...

How do I "add" strings in PHP - not concatenate, but "add" them. (as if each character was a base 36 numbers)

Unfortunately I inherited some code (c/c++) that does some string manipulation and now I need to copy/port that over to php so this functionality can be accessed over the internets. Specifically the functionality takes some arbitrary strings and "adds" them together. (the c code iterates down the character array and then does some ch...

MATLAB Array Manipulation

I'm trying to insert multiple values into an array using a 'values' array and a 'counter' array. For example, if: a=[1,3,2,5] b=[2,2,1,3] I want the output of some function c=somefunction(a,b) to be c=[1,1,3,3,2,5,5,5] Where a(1) recurs b(1) number of times, a(2) recurs b(2) times, etc... Is there a built-in function in MATLAB ...

PHP array manipulation

i have this array: Array ( 0 => "3_some val", 1 => "1_some other val", 2 => "0_val", 3 => "2_value", 4 => "4_other value" ) considering the above array, is there a way to do from that an array like this? Array ( 0 => "val", 1 => "some other val", 2 => "value", ...

A Simple PHP Array Manipulation

Hi guys! how would you turn this array: array( 0 => Title1, 1 => Title2, 3 => Address1, 4 => Address2, ) to this array: array ( 0 => array( 'title' => 'Title1' 'address' =>'Address1' ), 1 => array( 'title' => 'Title2', 'address' => 'Address2' ) ); when you were initially giv...

Distributing a function over a single dimension of an array in MATLAB?

I often find myself wanting to collapse an n-dimensional matrix across one dimension using a custom function, and can't figure out if there is a concise incantation I can use to do this. For example, when parsing an image, I often want to do something like this. (Note! Illustrative example only. I know about rgb2gray for this specific c...

Perl array manipulation

Is there a single line in perl which does some magic like this. Array = [100,200,300,400,500]; percent = 50% new_Array = [50,100,150,200,250]; That is, I give an array and specify a percent. And it should give me a new array with the given percent of original array values. should take care of odd numbers and give me either ceiling ...