Python Forum
"erlarge" a numpy-matrix to numpy-array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"erlarge" a numpy-matrix to numpy-array
#1
Hi all!

Is there a way to concatenate/append/"gluetogether" two (n*m-shaped) matrix into a single (n*m*2-shaped) array (with 3 axle), and not into an other (2n*m-shaped) or (n*2m-shaped) matrix?

I found a couple of websites about putting matrixes together, but these sites were about how to do it row~ or column~wise.
Reply
#2
So, you have two matrices of shape nxm and want to concatenate them by third axis and get one matrix of shape nxmx2.
Thats easy:
import numpy as np
A = np.random.rand(10, 20)
B = np.random.rand(10, 20)
C = np.dstack([A, B])
print(C.shape)
Reply
#3
Thank you!

This is exactly, what I want.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 288 Mar-26-2024, 02:18 PM
Last Post: snippsat
  [Numpy] Load date/time from .txt to 'datetime64' type. water 4 403 Mar-01-2024, 11:16 PM
Last Post: Gribouillis
  numpy.ufunc - Arguments missunderstand MarioBruza 0 785 Jan-11-2023, 05:03 AM
Last Post: MarioBruza
  reshaping 2D numpy array paul18fr 3 969 Jan-03-2023, 06:45 PM
Last Post: paul18fr
  Pandas dataframes and numpy arrays bytecrunch 1 1,292 Oct-11-2022, 08:08 PM
Last Post: Larz60+
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,528 Jul-19-2022, 06:31 AM
Last Post: paul18fr
Question about Numpy indexing. water 1 1,409 Jan-18-2022, 09:52 PM
Last Post: paul18fr
  numpy masking/filtering nilamo 3 3,414 Dec-04-2021, 10:28 PM
Last Post: nilamo
  numpy adding columns rwahdan 4 2,281 Sep-21-2021, 08:25 PM
Last Post: deanhystad
  numpy 2-dimentional rwahdan 3 2,059 Sep-21-2021, 07:40 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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