flatten

Flatten multidimensional array concatenating keys [duplicate]

最后都变了- 提交于 2019-11-26 13:57:31
问题 Possible Duplicate: PHP convert nested array to single array while concatenating keys? Get array's key recursively and create underscore seperated string Please, read the whole question before answering. I have this multidimensional array: $data = array( 'user' => array( 'email' => 'user@example.com', 'name' => 'Super User', 'address' => array( 'billing' => 'Street 1', 'delivery' => 'Street 2' ) ), 'post' => 'Hello, World!' ); I want it flatten, transformed into: $data = array( 'user.email' =

What is the difference between flatten and ravel functions in numpy?

懵懂的女人 提交于 2019-11-26 11:59:59
import numpy as np y = np.array(((1,2,3),(4,5,6),(7,8,9))) OUTPUT: print(y.flatten()) [1 2 3 4 5 6 7 8 9] print(y.ravel()) [1 2 3 4 5 6 7 8 9] Both function return the same list. Then what is the need of two different functions performing same job. IanH The current API is that: flatten always returns a copy. ravel returns a view of the original array whenever possible. This isn't visible in the printed output, but if you modify the array returned by ravel, it may modify the entries in the original array. If you modify the entries in an array returned from flatten this will never happen. ravel

XML shredding via XSLT in Java

放肆的年华 提交于 2019-11-26 11:34:10
问题 I need to transform large XML files that have a nested (hierarchical) structure of the form <Root> Flat XML Hierarchical XML (multiple blocks, some repetitive) Flat XML </Root> into a flatter (\"shredded\") form, with 1 block for each repetitive nested block. The data has numerous different tags and hierarchy variations (especially in the number of tags of the shredded XML before and after the hierarchical XML), so ideally no assumption should be made about tag and attribute names, or the

JavaScript flattening an array of arrays of objects

不打扰是莪最后的温柔 提交于 2019-11-26 11:09:17
问题 I have an array which contains several arrays, each containing several objects, similar to this. [[object1, object2],[object1],[object1,object2,object3]] Here is a screenhot of the object logged to the console. What would be the best approach to flattening this out so it just an array of objects? I\'ve tried this with no luck: console.log(searchData); var m = [].concat.apply([],searchData); console.log(m); searchData logs out the screenshot above, but m logs out [ ] Here is the actual

Python 3 replacement for deprecated compiler.ast flatten function

帅比萌擦擦* 提交于 2019-11-26 08:53:04
问题 What\'s the recommended way to flatten nested lists since the deprecation of the compiler package? >>> from compiler.ast import flatten >>> flatten([\"junk\",[\"nested stuff\"],[],[[]]]) [\'junk\', \'nested stuff\'] I know that there are a few stack overflow answers for list flattening, but I\'m hoping for the pythonic, standard package, \"one, and preferably only one, obvious way\" to do this. 回答1: Your stated function takes a nested list and flattens that into a new list. To flatten an

Convert 2 dimensional array

拜拜、爱过 提交于 2019-11-26 08:27:27
问题 What is selectMany.ToArray() method? Is it a built in method in C# ? I need to convert two dimensional array to one dimensional array. 回答1: If you mean a jagged array ( T[][] ), SelectMany is your friend. If, however, you mean a rectangular array ( T[,] ), then you can just enumerate the date data via foreach - or: int[,] from = new int[,] {{1,2},{3,4},{5,6}}; int[] to = from.Cast<int>().ToArray(); 回答2: SelectMany is a projection operator, an extension method provided by the namespace System

Flatten a list in Prolog

三世轮回 提交于 2019-11-26 07:47:09
问题 I\'ve only been working with Prolog for a couple days. I understand some things but this is really confusing me. I\'m suppose to write a function that takes a list and flattens it. ?- flatten([a,[b,c],[[d],[],[e]]],Xs). Xs = [a,b,c,d,e]. % expected result The function takes out the inner structures of the list. This is what I have so far: flatten2([],[]). flatten2([Atom|ListTail],[Atom|RetList]) :- atom(Atom), flatten2(ListTail,RetList). flatten2([List|ListTail],RetList) :- flatten2(List

How to “flatten” or “index” 3D-array in 1D array?

我是研究僧i 提交于 2019-11-26 07:24:53
问题 I am trying to flatten 3D array into 1D array for \"chunk\" system in my game. It\'s a 3D-block game and basically I want the chunk system to be almost identical to Minecraft\'s system (however, this isn\'t Minecraft clone by any measure). In my previous 2D-games I have accessed the flattened array with following algorithm: Tiles[x + y * WIDTH] However, this obviously doesn\'t work with 3D since it\'s missing the Z-axis. I have no idea how to implement this sort of algorithm in 3D-space.

Turn Pandas Multi-Index into column

吃可爱长大的小学妹 提交于 2019-11-26 06:17:15
问题 I have a dataframe with 2 index levels: value Trial measurement 1 0 13 1 3 2 4 2 0 NaN 1 12 3 0 34 Which I want to turn into this: Trial measurement value 1 0 13 1 1 3 1 2 4 2 0 NaN 2 1 12 3 0 34 How can I best do this? I need this because I want to aggregate the data as instructed here, but I can\'t select my columns like that if they are in use as indices. 回答1: The reset_index() is a pandas DataFrame method that will transfer index values into the DataFrame as columns. The default setting

Convert nested JSON array into separate columns in CSV file

风流意气都作罢 提交于 2019-11-26 04:55:32
问题 I have a JSON file that looks like this: { \"id\": 10011, \"title\": \"Test procedure\", \"slug\": \"slug\", \"url\": \"http://test.test\", \"email\": \"test@test.com\", \"link\": \"http://test.er\", \"subject\": \"testing\", \"level\": 1, \"disciplines\": [ \"discipline_a\", \"discipline_b\", \"discipline_c\" ], \"areas\": [ \"area_a\", \"area_b\" ] }, I was trying to use the following command to convert that into the CSV file: (Get-Content \"PATH_TO\\test.json\" -Raw | ConvertFrom-Json)|