“Convertir la lista 2D a 1d Python” Código de respuesta

Convertir la lista 2D a 1d Python

import itertools

a = [[1, 2], [3, 4], [5, 6]]
list(itertools.chain.from_iterable(a))

Output:- [1, 2, 3, 4, 5, 6]
Sundar

convertir 2d aray en 1d usando python

import numpy as np

twoDAry = [6.4],[5.9],[5.5],[5.3],[5.1],[4.9],[4.5],[4.5],[4.5],[4.3],[4.2],[3.8],[3.5],[2.8],[2.8],[2.8]
twoDAry = np.array(twoDAry)
print(twoDAry.reshape(1, -1)[0])

# Output
# [6.4 5.9 5.5 5.3 5.1 4.9 4.5 4.5 4.5 4.3 4.2 3.8 3.5 2.8 2.8 2.8]
Red Team

pase la matriz 2D a 1d Python

# Create a 2D Numpy Array.
arr = np. array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
# convert 2D array to a 1D array of size 9.
flat_arr = np. reshape(arr, 9)
happy penguin

Respuestas similares a “Convertir la lista 2D a 1d Python”

Preguntas similares a “Convertir la lista 2D a 1d Python”

Más respuestas relacionadas con “Convertir la lista 2D a 1d Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código