- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compute a matrix transpose with Einstein summation convention in Python
The einsum() method evaluates the Einstein summation convention on the operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. In implicit mode einsum computes these values. In explicit mode, einsum provides further flexibility to compute other array operations that might not be considered classical Einstein summation operations, by disabling, or forcing summation over specified subscript labels.
To compute a matrix transpose with Einstein summation convention, use the numpy.einsum() method in Python. The 1st parameter is the subscript. It specifies the subscripts for summation as comma separated list of subscript labels. The 2nd parameter is the operands. These are the arrays for the operation.
Steps
At first, import the required libraries −
import numpy as np
Creating a numpy array using the arange() and reshape() method −
arr = np.arange(16).reshape(4,4)
Display the array −
print("Our Array...
",arr)
Check the Dimensions −
print("
Dimensions of our Array...
",arr.ndim)
Get the Datatype −
print("
Datatype of our Array object...
",arr.dtype)
Get the Shape −
print("
Shape of our Array object...
",arr.shape)
To compute a matrix transpose with Einstein summation convention, use the numpy.einsum() method in Python −
print("
Result (transpose)...
",np.einsum('ji', arr))
Example
import numpy as np # Creating a numpy array using the arange() and reshape() method arr = np.arange(16).reshape(4,4) # Display the array print("Our Array...
",arr) # Check the Dimensions print("
Dimensions of our Array...
",arr.ndim) # Get the Datatype print("
Datatype of our Array object...
",arr.dtype) # Get the Shape print("
Shape of our Array object...
",arr.shape) # To compute a matrix transpose with Einstein summation convention, use the numpy.einsum() method in Python. print("
Result (transpose)...
",np.einsum('ji', arr))
Output
Our Array... [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11] [12 13 14 15]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (4, 4) Result (transpose)... [[ 0 4 8 12] [ 1 5 9 13] [ 2 6 10 14] [ 3 7 11 15]]
- Related Articles
- Matrix Vector multiplication with Einstein summation convention in Python
- Get the trace of a matrix with Einstein summation convention in Python
- Extract the diagonal of a matrix with Einstein summation convention in Python
- Scalar multiplication with Einstein summation convention in Python
- Tensor contraction with Einstein summation convention in Python
- Array axis summations with Einstein summation convention in Python
- Vector inner product with Einstein summation convention in Python
- Vector outer product with Einstein summation convention in Python
- Transpose a matrix in Python?
- How to Transpose a Matrix using Python?
- Compute the multiplicative inverse of a matrix object with matrix() in Python
- Find the transpose of a matrix in Python Program
- Transpose a matrix in Java
- Transpose a matrix in C#
- How to Transpose a matrix in Single line in Python?
