Published on January 26, 2024By DeveloperBreeze

Python Example: Reshaping Arrays with NumPy

The following Python code demonstrates how to reshape a one-dimensional array into a two-dimensional array using NumPy:

import numpy as np

# Define a one-dimensional array
arr = np.array([1, 2, 3, 4, 5, 6])

# Reshape the array into a 2x3 matrix
reshaped_arr = arr.reshape(2, 3)
print(reshaped_arr)

Comments

Please log in to leave a comment.

Continue Reading:

Append Data to JSON File

Published on January 26, 2024

jsonpython

Create and Save Random Color Grid as PNG Image

Published on January 26, 2024

python

Filtering and Selecting Elements in NumPy Array

Published on January 26, 2024

python

Calculate Mean and Standard Deviation of NumPy Array

Published on January 26, 2024

python

Create a NumPy 1D Array

Published on January 26, 2024

python

Calculate Sum of Numbers in Array

Published on January 26, 2024

csharp

Remove Duplicates from Array Using Set

Published on January 26, 2024

javascript

Find Maximum Number in Array Using Math.max

Published on January 26, 2024

javascript

Find Maximum Number in List Using max() Function

Published on January 26, 2024

python