Skip to content

np.concatenate() - Concatenate multiple arrays #49

@TheWolf313

Description

@TheWolf313

Syntax:
np.concatenate((a1, a2, ...), axis=0)

a1, a2, ...: Sequence of arrays to join.

axis: The axis along which the arrays will be joined. Default is 0.

All arrays must have the same shape except in the dimension corresponding to axis.

import numpy as np
arr1 = np.array([1, 2])
arr2 = np.array([3, 4])
concat_arr = np.concatenate((arr1, arr2))
print(concat_arr)

[1 2 3 4]

import numpy as np
a = np.array([[1, 2]])
b = np.array([[3, 4]])
concat_2d = np.concatenate((a, b), axis=0)
print(concat_2d)

[[1 2]
[3 4]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions