You might need to check out numpy.flatten and numpy.ravel, both return a 1-d array from an n-d array.

Furthermore, if you're not going to modify the returned 1-d array, I suggest you use numpy.ravel, since it doesn't make a copy of the array, but just return a view of the array, which is much faster than numpy.flatten.

>>>a = np.arange(10000).reshape((100,100))

>>>%timeit a.flatten()
100000 loops, best of 3: 4.02 µs per loop

>>>%timeit a.ravel()
1000000 loops, best of 3: 412 ns per loop

Also check out this post.

Answer from Alcott on Stack Overflow
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.flatten.html
numpy.ndarray.flatten — NumPy v2.5.dev0 Manual
>>> import numpy as np >>> a = np.array([[1,2], [3,4]]) >>> a.flatten() array([1, 2, 3, 4]) >>> a.flatten('F') array([1, 3, 2, 4])
Discussions

Python 3.5: Flatten out array then reconstruct array
Just set the shape. my_array.shape = (-1,3) #flatten my_array.shape = (605, 700, 3) #unflatten More on reddit.com
🌐 r/learnpython
7
1
August 3, 2016
Flatten array recursively in python - Stack Overflow
Is your first "array" (actually it is a nested list, not an array in Python terminology) to be taken as input, or can you simply start from the items to permutate ("a", "b", "c", ...)? ... You can write a recursive function in order to flatten the list. More on stackoverflow.com
🌐 stackoverflow.com
October 12, 2021
Python Challenge - Flatten an Array
This community-built FAQ covers the “Flatten an Array” code challenge in Python. You can find that challenge here, or pick any challenge you like from our list. Top Discussions on the Python challenge Flatten an Array There are currently no frequently asked questions or top answers associated ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
0
November 12, 2021
Question regarding numpy.flatten()
The error highlights this line right here: x_test = np.delete(np.genfromtxt(input_file2, dtype=int),len(y_train[0])-1,1) and explicitly points to len(y_train[0]) as being the source of the error. If you print out y_train[0], you get 127900, this is a number, not any kind of sequence. After deleting from and flattening y_train you're left with a single dimensional array. This means y_train[0] is an element, not a nested list, so when you then try to call len(y_train[0]), you're calling len() on a single number, not a nested list. More on reddit.com
🌐 r/learnpython
8
3
June 4, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › machine learning › numpy-ndarray-flatten-function-python
Numpy ndarray.flatten() function in Python - GeeksforGeeks
July 12, 2025 - The flatten() function is used to convert a multi-dimensional NumPy array into a one-dimensional array. It creates a new copy of the data so that original array stays unchanged. If your array has rows and columns or even more dimensions, then ...
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .flatten()
Python:NumPy | ndarray | .flatten() | Codecademy
April 10, 2025 - The .flatten() method converts a multi-dimensional NumPy array into a one-dimensional array. This method creates a copy of the original array with all elements arranged in a single dimension while preserving the values and their order.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Flatten an array with ravel() and flatten() | note.nkmk.me
February 2, 2024 - Specifying an ndarray as the first argument to np.ravel() returns a flattened ndarray. a = np.arange(12).reshape(3, 4) print(a) # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] print(np.ravel(a)) # [ 0 1 2 3 4 5 6 7 8 9 10 11] print(type(np.ravel(a))) # <class 'numpy.ndarray'> ... The argument can be any array-like object, including Python's built-in list type.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.matrix.flatten.html
numpy.matrix.flatten — NumPy v2.1 Manual
A copy of the matrix, flattened to a (1, N) matrix where N is the number of elements in the original matrix.
🌐
Reddit
reddit.com › r/learnpython › python 3.5: flatten out array then reconstruct array
r/learnpython on Reddit: Python 3.5: Flatten out array then reconstruct array
August 3, 2016 -

I have a numpy array with initial dimensions of [605, 700, 3]. I then reshape the array such that the dimensions are [(605*700), 3] (basically a flat list of 3 item tuples). The array is flattened so that it can be fed into a variety of analysis functions. However, I ultimately need to reconstruct the array so that it is [605, 700, 3]. How would I go about doing this?

EDIT: I forgot to mention that I need the values to return to their starting indices when the array is reconstructed.

Find elsewhere
🌐
CodingNomads
codingnomads.com › np-reshape-np-flatten-np-ravel
NumPy Array Manipulation: np.reshape, np.flatten, np.ravel ...
While NumPy flatten() returns a copy of the array, NumPy ravel() and Numpy reshape(-1) generally return a view unless they need to make a copy for memory layout reasons.
🌐
Programiz
programiz.com › python-programming › numpy › methods › flatten
NumPy flatten()
The flatten() method flattens a NumPy array without changing its data. The flatten() method flattens a NumPy array without changing its data. Example import numpy as np # create a two-dimensional array array1 = np.array([[0, 1], [2, 3]]) # flatten an array array2 = array1.flatten() print(array2) ...
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.flatten.html
numpy.ndarray.flatten — NumPy v2.2 Manual
>>> import numpy as np >>> a = np.array([[1,2], [3,4]]) >>> a.flatten() array([1, 2, 3, 4]) >>> a.flatten('F') array([1, 3, 2, 4])
🌐
iO Flood
ioflood.com › blog › python-flatten-list-how-to-flatten-nested-lists-in-python
Python Flatten List | How To Flatten Nested Lists in Python
June 27, 2024 - Handling nested lists consistently is a challenge we faced when automating processes at IOFLOOD. We have found the best way to simplify nested data in Python is with list flattening, which converts nested lists into a single-level list.
🌐
Tutorial Teacher
tutorialsteacher.com › articles › how-to-flatten-list-in-python
How to flatten list of lists in Python?
Recall that the + symbol is defined ... of a lambda function, we can also use the concat() function defined in the operator module as an argument to cumulatively append the sublists to flatten....
🌐
GitHub
gist.github.com › 6e5f86d253776f1d68da
Flatten an array of arrays with Python · GitHub
Flatten an array of arrays with Python · Raw · python-flatten-array.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
DZone
dzone.com › data engineering › data › python: equivalent to flatmap for flattening an array of arrays
Python: Equivalent to flatMap for Flattening an Array of Arrays
May 9, 2015 - from itertools import chain, imap flattened_episodes = chain.from_iterable( imap(lambda episode: [{"id": episode["id"], "topic": topic} for topic in episode["topics"]], episodes)) for episode in flattened_episodes: print episode
🌐
GeeksforGeeks
geeksforgeeks.org › python-flatten-a-2d-numpy-array-into-1d-array
Python | Flatten a 2d numpy array into 1d array - GeeksforGeeks
February 3, 2023 - Time complexity: O(n), where n is the total number of elements in the 2D numpy array. Auxiliary space: O(n), as the result array is also of size n. The flatten function returns a flattened 1D array, which is stored in the "result" variable.
🌐
Exercism
exercism.org › tracks › python › exercises › flatten-array › solutions
Community solutions for Flatten Array in Python on Exercism
Explore other people's solutions to Flatten Array in Python, and learn how others have solved the exercise.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions
Python Challenge - Flatten an Array - Frequently Asked Questions - Codecademy Forums
November 12, 2021 - This community-built FAQ covers the “Flatten an Array” code challenge in Python. You can find that challenge here, or pick any challenge you like from our list. Top Discussions on the Python challenge Flatten an Arr…
🌐
YouTube
youtube.com › watch
Flatten Deeply Nested Array - Leetcode 2625 - JavaScript 30-Day Challenge - YouTube
Solving Day 22 of the Leetcode 30-day javascript challenge. Today we learn about flattening arrays.🚀 https://neetcode.io/ - A better way to prepare for Codi...
Published   May 26, 2023