×

numpy.transpose() in Python

numpy.transpose() in Python

The numpy.transpose() permutes the dimensions of an array.

Syntax

numpy.transpose(a, axes=None)

Parameter

a : This parameter represents an input array.

axes : It is an optional parameter which by default, reverses the dimensions, otherwise permutes the axes according to the values given.

Return

This function returns the parameter ‘a’ with its axes permuted. A view is returned whenever possible.

Example 1

# Python Program explaining
# numpy.transpose() function
import numpy as np
# making a 3x3 array
val = np.array([[11, 12, 13],
                [14, 15, 16],
                [17, 18, 19]])
# value before transpose
print("Before transpose: \n",+val, end ='\n\n')
# value after transpose
print("After transpose: \n",+val.transpose())

Output

Before transpose:
[[11 12 13]
[14 15 16]
[17 18 19]]
After transpose:
[[11 14 17]
[12 15 18]
[13 16 19]]

Related Topics

numpy.loadtxt() Python

Python numpy.loadtxt() The loadtxt() function of Python numpy class loads the data from a text fileand provides a fast reader for simple text files. Syntax numpy.loadtxt(fname, dtype=<class'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None) Parameter fname : This parameter represents a file, filename, or...

2 minutes read.

numpy.full() in Python

numpy.full() in Python The full() method of Python numpy class returns a new array of specified shape and type, filled with fill_value. Syntax numpy.full(shape, fill_value, dtype=None, order='C') Parameter shape:This parameter represents the number of rows order :The order parameter can...

1 minute read.

numpy.ndarray.flat() in Python

numpy.ndarray.flat() in Python The numpy.ndarray.flat() returns a 1-D iterator over the array. This function is not a subclass of, Python’s built-in iterator object, otherwise it will act the same as a...

1 minute read.

numpy.swapaxes() in Python

numpy.swapaxes() in Python The numpy.swapaxes() function interchanges the two specified axes of the given array. Syntax numpy.swapaxes(a, axis1, axis2) Parameter The numpy.swapaxes() method consists of three parameters, which are as follows: a : This parameter represents the Input array. axis1 : It represents...

1 minute read.

numpy.delete() in Python

numpy.delete() in Python The numpy.delete() function returns a new array with sub-arrays along an axis deleted. For 1-D array, this function returns those entries which are not returned by arr[obj]. Syntax numpy.delete(arr, obj, axis=None) Parameter arr: This parameter returns...

2 minutes read.

numpy.trim_zeros() in Python

numpy.trim_zeros() in Python The numpy.trim_zeros() trims the leading and/or trailing zeros from a 1-D array or sequence. Syntax numpy.trim_zeros(filt, trim='fb') Parameter The numpy.trim_zeros() function consists of two parameters, which are as follows: filt : This parameter represents the 1-D...

1 minute read.

numpy.unique() in Python

numpy.unique() in Python The numpy.unique() function finds the unique elements of an array and returns the sorted unique elements for the specified array.  Syntax numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None) Parameter ar : This parameter returns an Input array.If the aaray is...

2 minutes read.

numpy.resize() in Python

numpy.resize() in Python The numpy.resize() returns a new array with the specified shape. If the new array is larger than the original array, then the new array is filled with repeated...

1 minute read.

numpy.stack() in Python

numpy.stack() in Python The numpy.stack() function joins a sequence of arrays along a new axis. Syntax numpy.stack(arrays, axis=0, out=None) Parameter arrays: This parameter represents a sequence of the array where each array have the same shape. axis: It is an...

1 minute read.

numpy.fromiter() in Python

numpy.fromiter() in Python The fromiter() function of Python numpy class creates a ndarray by using an iterable object. It returns a one-dimensional ndarray object. Syntax numpy.fromiter(iterable, dtype, count=-1) Parameter The numpy.frombuffer() method consists of three parameters, which...

1 minute read.

numpy.ndarray.flatten() in Python

numpy.ndarray.flatten() in Python The numpy.ndarray.flatten() returns a copy of the array collapsed into 1-dimension. Syntax ndarray.flatten(order='C') Parameter The numpy. ndarray.flatten() method consists of one parameter, which is as follows: order : This parameter can be either...

1 minute read.

numpy.expand_dims() in Python

numpy.expand_dims() in Python The numpy.expand_dims() function expands the shape of an array. It Inserts a new axis that appears at the axis position in the expanded array shape. Syntax numpy.expand_dims(a, axis) Parameter The numpy.expand_dims() function has two parameters...

1 minute read.

numpy.hstack() in Python

numpy.hstack() in Python The numpy.hstack() function stacks the arrays in a sequence horizontally (column wise). Syntax numpy.hstack(tup) Parameter tup: This parameter represents the sequence of ‘ndarrays’ where the arrays must have the same shape, except 1-D...

1 minute read.

numpy.transpose() in Python

numpy.transpose() in Python The numpy.transpose() permutes the dimensions of an array. Syntax numpy.transpose(a, axes=None) Parameter a : This parameter represents an input array. axes : It is an optional parameter which by default, reverses the dimensions, otherwise permutes the axes according...

1 minute read.

numpy.atleast_1d() in Python

numpy.atleast_1d() in Python The numpy.atleast_1d() function converts the inputs to arrays with at least one dimension. Syntax numpy.atleast_1d(*arys) Parameter arys1, arys2, … : This parameter represents one or more input arrays. Return This function returns an array, or list...

1 minute read.

numpy.flip() in Python

numpy.flip() in Python The numpy.flip() function is used to reverse the order of elements in an array along the given axis where the shape of the array is preserved, but the...

1 minute read.

Numpy.copy() in Python with Example

Numpy.copy() in Python The copy() function of Python numpy class returns an array copy for the given object. Syntax numpy.copy(a, order='K') Parameter a: It represent the array_like input data. order :  This parameter controls the memory layout of...

1 minute read.

numpy.tile() in Python

numpy.tile() in Python The numpy.tile() function constructs an array by repeating the parameter ‘A’  the number of times as specified by the ‘reps’ parameter. Syntax numpy.tile(A, reps) Parameter The numpy.tile() function consists of two parameters, which...

1 minute read.

numpy.column_stack() in Python

numpy.column_stack() in Python The numpy.column_stack() function stacks  the 1-D arrays as columns into a 2-D array. It takes a sequence of 1-D arrays and stacks them as columns to make a...

1 minute read.

numpy.ones() in Python

numpy.ones() in Python The ones() method of Python numpy class returns a new array of given shape and type, filled with ones. Syntax numpy.ones(shape, dtype=None, order='C') Parameter The numpy.ones() method consists of three parameters, which are as...

1 minute read.