×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

How to Transpose a 1D NumPy Array?

In this tutorial, we will learn how to transpose a 1D NumPy array? By Pranit Sharma Last updated : May 25, 2023

Given a 1D NumPy array, we have to transpose it.

Transpose a 1D NumPy Array

  1. First, convert the 1D vector into a 2D vector so that you can transpose it. It can be done by slicing it with np.newaxis during the creation of the array.
  2. And, then by using the .T method, you can transpose it.

Python program to transpose a 1D NumPy array

# Import numpy
import numpy as np

# Creating numpy array
arr = np.array([10, 20, 30, 40, 50])[np.newaxis]

# Printing the original array
print("Original array (arr):\n",arr,"\n")

# Transposing the NumPy array
transpose_arr = arr.T

# Display result
print("Transpose Array (transpose_arr):\n",transpose_arr)

Output

The output of the above program is:

Original array (arr):
 [[10 20 30 40 50]] 

Transpose Array (transpose_arr):
 [[10]
 [20]
 [30]
 [40]
 [50]]

Python NumPy Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.