[PYTHON] Matrix concatenation with Numpy

[Addition] I wrote a memo like this when I was a student, but please calmly use `` `np.concatenate```: https://docs.scipy.org/doc/numpy/reference /generated/numpy.concatenate.html


Make a note because I often forget which one.

>>> import numpy as np
>>> a = np.array([[1,2,3], [4,5,6]])
>>> b = np.array([[7, 8, 9], [10, 11, 12]])
>>> c = np.array((1, 2, 3))
>>> d = np.array((4, 5, 6))

>>> a
array([[1, 2, 3],
       [4, 5, 6]])

>>> b
array([[ 7,  8,  9],
       [10, 11, 12]])

>>> c
array([1, 2, 3])

>>> d
array([4, 5, 6])

>>> np.r_[a, b]
array([[ 1,  2,  3],
       [ 4,  5,  6],
       [ 7,  8,  9],
       [10, 11, 12]])

>>> np.c_[a, b]
array([[ 1,  2,  3,  7,  8,  9],
       [ 4,  5,  6, 10, 11, 12]])

>>> np.r_[c, d]
array([1, 2, 3, 4, 5, 6])

>>> np.c_[c, d]
array([[1, 4],
       [2, 5],
       [3, 6]])

Recommended Posts

Matrix concatenation with Numpy
Try matrix operation with NumPy
Moving average with numpy
Numpy leave? !! Partial differential of matrix with Sympy
Getting Started with Numpy
Learn with Cheminformatics NumPy
Hamming code with numpy
Regression analysis with NumPy
Extend NumPy with Rust
Let's transpose the matrix with numpy and multiply the matrices.
I tried Smith standardizing an integer matrix with Numpy
Kernel regression with Numpy only
I wrote GP with numpy
CNN implementation with just numpy
Artificial data generation with numpy
[Python] Calculation method with numpy
Diffusion equation animation with NumPy
Debt repayment simulation with numpy
Implemented SMO with Python + NumPy
Stick strings together with Numpy
Handle numpy arrays with f2py
Use OpenBLAS with numpy, scipy
Python3 | Getting Started with numpy
Implementing logistic regression with NumPy
Performance comparison between 2D matrix calculation and for with numpy
Visualization of matrix created by numpy
Perform least squares fitting with numpy.
Matrix representation with Python standard input
Getting Started with Sparse Matrix with scipy.sparse
Draw a beautiful circle with numpy
Implement Keras LSTM feedforward with numpy
Extract multiple elements with Numpy array
Cosine similarity matrix? You can get it right away with NumPy
[Python] Matrix multiplication processing time using NumPy
Read and write csv files with numpy
Create bins with NumPy, get data-bin correspondence
Create Excel file with Python + similarity matrix
Graph trigonometric functions with numpy and matplotlib
I made a life game with Numpy
Speeding up numerical calculations with NumPy: Basics
Read a character data file with numpy
Handle numpy with Cython (method by memoryview)
Use multithreaded BLAS / LAPACK with numpy / scipy
Create a matrix with PythonGUI (text box)
Comparison of matrix transpose speeds with Python
[Python] Giga Code 2019 D --Building a house (manipulate with numpy as a matrix !!!) [AtCoder]