Python Forum
How to vstack matrixs in numpy with different numbers of columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to vstack matrixs in numpy with different numbers of columns
#1
I want to stack matrixs together with different numbers of columns

The way I can think of is:
1.Find out how many columns in a
2.Add empty columns to b
3.Stack them together


Is there another way to make it simpler?


import numpy as np

a = np.array([["A1", "B1", "C1"], ["A1", "B1", "C1"]])
b = np.array([["A2", "B2"], ["A2", "B2"]])
c = np.array([["A3", "B3"], ["A3", "B3"]])

print(np.vstack((a, b))) #This would not allowed, because a and b have different columns

# The following Result is wanted
# [['A2' 'B2' 'C2']
#  ['A2' 'B2' 'C2']
#  ['A3' 'B3' '']
#  ['A3' 'B3' '']]
Reply


Messages In This Thread
How to vstack matrixs in numpy with different numbers of columns - by hlhp - Jun-17-2019, 04:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Numpy Play with Rows and Columns of a Matix quest 6 2,983 Nov-05-2020, 09:08 PM
Last Post: quest
  Read strings and numbers in columns from a file suvadip 4 2,963 Aug-11-2020, 09:37 PM
Last Post: suvadip
  output a list of random numbers 'x' columns wide adityavpratap 4 3,068 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,781 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

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