Questions tagged [flatten]

Flattening refers to either reducing a multi-dimensional array to a single dimension or to reducing a class and class methods to handle based function calls.

1554 questions
0
votes
1 answer

Flatten array of structs into several arrays in C++

Source code to understand the situation: struct s { int i; float f }; const int cnt = 10; s *source = new s[cnt]; /*... fill source ...*/ int *dest_i = new int[cnt]; float *dest_f = new float[cnt]; for (int x = 0; x < cnt; x++) { …
Yarg
  • 5,586
  • 2
  • 17
  • 22
0
votes
1 answer

Piglatin limit and flatten produces wrong results

B = GROUP A BY state; C = FOREACH B { DA = ORDER A BY population DESC; DB = LIMIT DA 5; GENERATE FLATTEN(group), FLATTEN(DB.name), FLATTEN(DB.population); } The problem is…
user1855165
  • 289
  • 1
  • 8
  • 22
0
votes
1 answer

How to flatten the entire package hierarchy?

If I want to flatten all my package hierarchy, how can I proceed and what are the gotchas? Note that this question is not about why I want to do this, but how. Valid reasons, for example, would include (but would not be limited to) several of the…
Cedric Martin
  • 5,945
  • 4
  • 34
  • 66
0
votes
1 answer

Flattening Images in Iphone SDK

I am trying to save more then 1 image with a background image into a single image and then saving it out. I found out how to flatten the images, but the images I added on top of the background are not appearing in the correct position when…
CodeMonkey
0
votes
2 answers

What does it mean to flatten an iterator?

I would like to know what it means to flatten e.g. flatten an iterator of iterators. Can you tell me? Are there any C/Java/Python idioms for it?
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
2 answers

Push elements from two arrays in an alternating fashion to form a new flat array

I need a function that can intersect 2 arrays for example: $Array1 = array(1,2,3); $Array2 = array(5,6); and results in: array(1,5,2,6,3); What I have so far is this
Master345
  • 2,250
  • 11
  • 38
  • 50
0
votes
2 answers

how to flatten/penetrate an arbitrarily structured nested list in Python?

Possible Duplicate: Flatten (an irregular) list of lists in Python for instance, from: [[1,2,3],'a',[[4],[5,6],7]] we want to flatten/penetrate the structure and get all the elements at bottom listed in a line: [1,2,3,'a',4,5,6,7]
Matt
  • 741
  • 1
  • 6
  • 17
0
votes
1 answer

Common Lisp - flatting a list that may contain symbols

This is #7 of of 99 Lisp problems: transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). I have tried several solutions, e.g from #2680864 or from here. They all work, but I…
0
votes
1 answer

Duplicate items in collection by field flattening

I have a collection: [ A { 'a' => '1', 'b' => ['1', '2']} B { 'a' => '2', 'b' => ['1','2','3']} ] I'm searching for a function to 'duplicate' items in this collection to make next result: [ A1 { 'a' => '1', 'b' => '1'} A2 { 'a' => '1', 'b' =>…
Dima
  • 6,721
  • 4
  • 24
  • 43
-1
votes
0 answers

flatten nested object with model type

I need to flatten a nested object. I've got my missingData like this: { a:2, b: { c:3 } } And I need ... { a:2, b:3 } but my model is like this: request { a: string, b: user, c: string } user { id: string } I tried this: let…
John
  • 1
  • 1
-1
votes
2 answers

Calling the main function inside a callback function in javascript

I am struggling to understand the following code: let myArray = ["J", "a", "v", ["a", "scrip"], "t"]; const flatten = (myArray) => { return myArray.reduce((flat, arry) => { return Array.isArray(arry) ? flat.concat(flatten(arry)) :…
-1
votes
2 answers

Get flatten 2d array from a multidimensional array with parent-child relationships and inconsistent scalar data

I have a multidimensional array with parent-child relationships and I want to flatten its data into a 2d array of the scalar data from each level using recursion. [ 'children' => [ [ 'id' => 123, 'title' =>…
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
-1
votes
3 answers

How does flatten behave diffrently with Vec> and Vec> or Vec> in rust

The official docs of iter::flatten states : An iterator that flattens one level of nesting in an iterator of things that can be turned into iterators. But for this code: if let Ok(entries) = fs::read_dir("/path/to/dir") { for entry in…
-1
votes
2 answers

How do i store keys while flattening?

I have a nested JSON object which is of the format [{ firstLevelKey1 : [{ dataType : 'String' },{ value : 'someString' },{ someKey : 'someValue' }] },{ firstLevelKey2:[{ dataType : 'Object' },{ value : [{ …
Manoj HT
  • 54
  • 7
-1
votes
3 answers

Flatten a 2d array while preserving numeric associative row keys

I need to flatten a 2d array to become a 1d array without losing my numeric 2nd level keys in the process. Sample data: [ [2015 => '2015'], [2016 => '2016'], [2017 => '2017'], [2018 => '2018'], [2019 => '2019'], [2020 =>…
K1m4
  • 5
  • 2