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.
Questions tagged [flatten]
1554 questions
-1
votes
4 answers
Flatten all subarrays in an array
I got a numpy array X which have shape (2 , 2 , 3) like this:
X = [[[1 , 2 , 3 ]
[4 , 5 , 6]] ,
[[7 , 8 , 9 ]
[10, 11, 12 ]],
I want to flatten all subarrays and turn X to the shape of (2 , 6) which is represented like…

Miku
- 79
- 1
- 7
-1
votes
2 answers
Using flatten! on an array of arrays not working
I am building a script that takes in a column from a CSV that can contain 0 or more ID numbers. I have created an array of the column, however, since some cells have no ID number and some have multiple,I have an array of arrays.
I want to create an…

Belle
- 11
- 5
-1
votes
1 answer
SQL convert rows to columns and flatten
I have been looking for the solution to this in PIVOT, UNPIVOT, and others but still don't see my scenario. I have items in a table. For simplicity we'll just say PartNum, Desc. These things can be customized. The attributes like color, height,…

Hey Mikey
- 101
- 6
-1
votes
2 answers
How do I create a flat array from a nested array of objects in javascript recursively?
I want to convert the following data structure:
const data = [
{
regions: ['United States', 'Canada']
},
{
regions: ['United States']
},
{
prop1: {
regions: ['Canada']
}
},
{
prop2: [
{
regions:…

Steven Grimaldo
- 75
- 9
-1
votes
1 answer
How can I "unpack" a nested object as an array?
I have an object that consists of iterable items (the keys are just datestrings). Some of these objects have more than one item.
I want to flatten every object so that I only keep objects with one dimension.
Basically, I want data to look like…

medicengonzo
- 479
- 1
- 7
- 23
-1
votes
2 answers
How to flatten data numpy.ndarray in python
I have a numpy.ndarray data that looks like below and I want to flatten it out so that i can manipulate it. Please find my sample data below:
sample_data=[list([{'region': 'urn:li:region:9194', 'followerCounts': {'organicFollowerCount': 157,…

user86907
- 817
- 9
- 21
-1
votes
4 answers
How to convert an array containing arrays of objects to single array witht hose object using Ramda expressions?
I am having a difficult time, there is some bad mapping going on on my code.
I have an array containing array of objects like that :
[
[{a: 1, b: 2},{a: 1, b: 3} ],
[{a: 5, b: 2},{a: 2, b: 5}]
]
And I want to make like that :
[
{a: 1, b:…

TaouBen
- 1,165
- 1
- 15
- 41
-1
votes
2 answers
Python: How to flatten list of lists where each sublist is a contains a single float
I want to flatten my list that looks as follows:
generated = [[108.88114502], [19.29647502], [4.08611068], [52.33578872], [134.54672018], [14.22388561], [22.04375228]]
To something like this:
flat_list = [108.88114502, 19.29647502, 4.08611068,…

WibeMan
- 91
- 7
-1
votes
2 answers
How to Get First_Value(), Last_Value() and previous Date action for an Array object inside a VARIANT column SnowflakeSQL
I have a VARIANT column call 'REQUEST' in the table 'QWERTY' that contains an Array object inside a JSON like
{
"ID": "123123",
"workflowHistory": [
{
"id": "666",
"workflowType": "CCC",
…

STG
- 15
- 3
-1
votes
2 answers
JavaScript flatMap() error: "flatMap mapper function is not callable"
I am trying to flatten an array with the following code, but when I use .flatMap() I get the error:
Uncaught TypeError: flatMap mapper function is not callable
at Array.flatMap ()
const data = [
{ key1: 5, key3: 2 },
…

Max888
- 3,089
- 24
- 55
-1
votes
1 answer
How do I use the flat() method to get certain values in an array?
I'm taking an online course which uses a bot to correct JavaScript code. The challenge is to
Create an array a and make so that a.length === 2 is true,
a[0].length === 1 is true,,
and a.flat() should 'print out' ['a', 'b' 'c']
The bot output tells…
user10307250
-1
votes
1 answer
How to 'flatten' a multi dimensional array of unknown depth and length AND record it's parent-child relations?
I have a PHP array that looks like this:
Array
(
[0] => Array
(
[id] => 2
[name] => Item2
[children] => Array
(
[0] => Array
(
…

Artem
- 81
- 6
-1
votes
1 answer
How customized flattening the nested list from a list?
I have the following list :
all_lines [[(0, 0), (0, 7)],
[(20, 20), (0, 7)],
[(0, 0), (13, 20)],
[(20, 20), (13, 20)],
[(10, 0), (0, 17), (10, 10), (10, 17), (20, 0), (20, 17), (0, 20), (20, 7)]]
So I…

ash
- 55
- 5
-1
votes
1 answer
How can I convert a list with sublist into a uniform list (flattening)?
I have a list of coordinates as following:
temp = [((20.0, 15.076858380630263), (20.0, 16.92468707613784)), (5.430012747754155, 3.3503228946034667), (7.364023506893538, 7.013767290971433), (11.932318028181742, 8.766709807679579),…

ash
- 55
- 5
-1
votes
4 answers
Merge/Flatten 3rd level data to create an array of arrays
I have an array with 3 levels and I'd like to merge/flatten all 3rd level subarrays into one subarray/row on the 2nd level.
$array = [
[
'User' => [
'id' => 57341,
'updated' => null,
'userId' =>…

Pranay Kachhadiya
- 11
- 1