Python Forum
How convert multidimensional array to two dimensional array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How convert multidimensional array to two dimensional array
#2
I am not sure I understand you correctly, but
if you want to convert
[
array([[0,0,0],[0,0,0]]),
array([0,0,0])
]
to
array(
[0,0,0]
[0,0,0]
[0,0,0])
you can do this using numpy.vstack function, e.g.

import numpy as np
sample_data = [np.random.rand(np.random.randint(2, 4), 3) for s in range(10)]
sample_data.append(np.array([5,6,7]))
Ok, sample_data consists of arrays of different size with common number of columns 3,
so these arrays could be stacked using np.vstack:

np.vstack(sample_data)
Reply


Messages In This Thread
RE: How convert multidimensional array to two dimensional array - by scidam - Feb-20-2019, 05:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ndim array Sowmya 2 508 Apr-03-2024, 04:19 AM
Last Post: Sowmya
  [Numpy] How to store different data type in one numpy array? water 7 1,069 Mar-26-2024, 02:18 PM
Last Post: snippsat
  boolean array: looking for all rows where all is True paul18fr 4 1,376 Jan-04-2023, 09:58 PM
Last Post: paul18fr
  reshaping 2D numpy array paul18fr 3 1,214 Jan-03-2023, 06:45 PM
Last Post: paul18fr
  Turn list of arrays into an array of lists Cola_Reb 6 1,890 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
Question how to write a function that accepts a 1D array as a parameter in Python SuperNinja3I3 1 1,771 Jul-02-2022, 01:55 PM
Last Post: Larz60+
  replace sets of values in an array without using loops paul18fr 7 1,961 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  how to parse this array with pandas? netanelst 1 1,467 May-17-2022, 12:42 PM
Last Post: netanelst
  semantics of comma inside array brackets usercat123 2 1,500 Apr-23-2022, 09:08 AM
Last Post: usercat123
  RandomForest --ValueError: setting an array element with a sequence JaneTan 0 1,838 Sep-08-2021, 02:12 AM
Last Post: JaneTan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020