multidimensional-array

Sorting array by count of subarray

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 10:37:19
问题 I have an array looking like this: Array( ['some_first_category'] => Array( ['some_first_name'] => Array( [0]=>'first@email.com', [1]=>'second@email.com', [2]=>'third@email.com', [3]=>'fourth@email.com' ) ['some_second_name'] => Array ( [1]=>'first@email.com', [2]=>'second@email.com') ['some_third_name'] => Array( [1]=>'first@email.com', [2]=>'second@email.com', [3]=>'third@email.com', [4]=>'fourth@email.com' ) ['some_second_category'] => Array( ['some_first_name'] => Array( [0]=>'first@email

Flattening a JSON multi depty array in PHP

ぃ、小莉子 提交于 2019-12-30 10:35:29
问题 Good morning, given the below data structure (in JSON for ease of reading) [ { "parent": "root", "active": "1", "label": "Index", "route": "/", "children": [ { "parent": "/", "active": "1", "label": "Products", "route": "/products", "children": [ { "parent": "/products", "active": "0", "label": "Test", "route": "/test" } ] } ] }, { "parent": "root", "active": "1", "label": "404", "route": "/404" }, { "parent": "root", "active": "1", "label": "Login", "route": "/login" } ] I am having major

Is using realloc() on a dynamically allocated 2D array a good idea?

浪子不回头ぞ 提交于 2019-12-30 09:31:35
问题 I am mainly interested in the viability of shrinking such an array. I'm working on a project where I have used single malloc() calls to each create individual moderately large 2D arrays. (Each only few tens of MiB, at the largest.) The thing is that over the life of one of the arrays, its content dramatically shrinks in size (by more than half). Obviously, I could just leave the array size alone for the life of the program. (It's only a x MiB on a system with GiB of RAM available.) But, we

How can I “extract” values from a multidimensional array in a smart way?

 ̄綄美尐妖づ 提交于 2019-12-30 08:02:17
问题 I am using Ruby on Rails 3.2.2 and Ruby 1.9.2. Given the following multidimensional Array : [["value1", "value1_other"], ["value2", "value2_other"], ["value3", "value3_other"]] I would like to get ( note : I would like to "extract" only the first value of all "nested" Array s): ["value1", "value2", "value3"] How can I make that in a smart way? 回答1: You can use Array#collect to execute a block for each element of the outer array. To get the first element, pass a block that indexes the array.

How to convert an int[,] to byte[] in C#

穿精又带淫゛_ 提交于 2019-12-30 07:50:19
问题 How to convert an int[,] to byte[] in C#? Some code will be appreciated EDIT: I need a function to perform the following: byte[] FuncName (int[,] Input) 回答1: Since there is very little detail in your question, I can only guess what you're trying to do... Assuming you want to "flatten" a 2D array of ints into a 1D array of bytes, you can do something like that : byte[] Flatten(int[,] input) { return input.Cast<int>().Select(i => (byte)i).ToArray(); } Note the call to Cast : that's because

python: convert 2 dimension list of string to float

▼魔方 西西 提交于 2019-12-30 07:15:31
问题 I have a 2 dimension list of type string I'm trying to convert it to int. Things I've tried so far: [[float(i) for i in lst[j] for j in lst] with a for loop: for i in range(len(lst)): for j in range(len(lst[i])): lst[i][j]=float(lst[i][j]) 回答1: >>> nums = [['4.58416458379', '3.40522046551', '1.68991195077'], ['3.61503670628', '5.64553650642', '1.39648965337'], ['8.02595866276', '8.42455003038', '7.93340754534']] >>> [[float(y) for y in x] for x in nums] [[4.58416458379, 3.40522046551, 1

Searching for key in multidimensional array and returning path to it

北城以北 提交于 2019-12-30 07:10:12
问题 I need to find a specific key in an array, and return both its value and the path to find that key . Example: $array = array( 'fs1' => array( 'id1' => 0, 'foo' => 1, 'fs2' => array( 'id2' => 1, 'foo2' => 2, 'fs3' => array( 'id3' => null, ), 'fs4' => array( 'id4' => 4, 'bar' => 1, ), ), ), ); search($array, 'fs3'); // Returns ('fs1.fs2.fs3', array('id3' => null)) search($array, 'fs2'); // Returns ('fs1.fs2', array('id2' => 1, ... )) I've been able to recurse through the array to find the

Searching for key in multidimensional array and returning path to it

左心房为你撑大大i 提交于 2019-12-30 07:09:18
问题 I need to find a specific key in an array, and return both its value and the path to find that key . Example: $array = array( 'fs1' => array( 'id1' => 0, 'foo' => 1, 'fs2' => array( 'id2' => 1, 'foo2' => 2, 'fs3' => array( 'id3' => null, ), 'fs4' => array( 'id4' => 4, 'bar' => 1, ), ), ), ); search($array, 'fs3'); // Returns ('fs1.fs2.fs3', array('id3' => null)) search($array, 'fs2'); // Returns ('fs1.fs2', array('id2' => 1, ... )) I've been able to recurse through the array to find the

How to convert singleton array to a scalar value in Python?

ぐ巨炮叔叔 提交于 2019-12-30 05:47:38
问题 Suppose I have 1x1x1x1x... array and wish to convert it to scalar? How do I do it? squeeze does not help. import numpy as np matrix = np.array([[1]]) s = np.squeeze(matrix) print type(s) print s matrix = [[1]] print type(s) print s s = 1 print type(s) print s 回答1: You can use the item() function: import numpy as np matrix = np.array([[[[7]]]]) print(matrix.item()) Output 7 回答2: Numpy has a function explicitly for this purpose: asscalar >>> np.asscalar(np.array([24])) 24 This uses item() in

MultiDimensional Array in Objective c

て烟熏妆下的殇ゞ 提交于 2019-12-30 05:28:08
问题 EveryBody.. i want to create one 8*8 dimensional array in objective c.. ( [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], ) like that.. And also use as one of the object can moved in it.. Like want to move MOVE_ARRAY = array([0, 0], [0, 2]) And also check the array's any position like 5*6 or 4*3 any.. So, Can any one help me about how