Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Multiply matrices of complex numbers using NumPy in Python
Next article icon

Multiply matrices of complex numbers using NumPy in Python

Last Updated : 23 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to multiply two matrices containing complex numbers using NumPy but first, let's know what is a complex number. A Complex Number is any number that can be represented in the form of x+yj where x is the real part and y is the imaginary part. Multiplication of two complex numbers can be done using the below formula - 

(a+ib) \times (x+iy)=ax+i^2by+i(bx+ay)=ax-by+i(bx+ay) 

NumPy provides the vdot() method that returns the dot product of vectors a and b. This function handles complex numbers differently than dot(a, b).

Syntax:

numpy.vdot(vector_a, vector_b)

Example 1:

Python3
# importing numpy as library import numpy as np   # creating matrix of complex number x = np.array([2+3j, 4+5j]) print("Printing First matrix:") print(x)  y = np.array([8+7j, 5+6j]) print("Printing Second matrix:") print(y)  # vector dot product of two matrices z = np.vdot(x, y) print("Product of first and second matrices are:") print(z) 

Output:

Printing First matrix: [2.+3.j 4.+5.j] Printing Second matrix: [8.+7.j 5.+6.j] Product of first and second matrices are: (87-11j)

Time complexity: O(1)
Auxiliary space: O(1)

Example 2: Now suppose we have 2D matrix: 

Python3
# importing numpy as library import numpy as np   # creating matrix of complex number x = np.array([[2+3j, 4+5j], [4+5j, 6+7j]]) print("Printing First matrix:") print(x)  y = np.array([[8+7j, 5+6j], [9+10j, 1+2j]]) print("Printing Second matrix:") print(y)  # vector dot product of two matrices z = np.vdot(x, y) print("Product of first and second matrices are:") print(z) 

Output:

Printing First matrix: [[2.+3.j 4.+5.j]  [4.+5.j 6.+7.j]] Printing Second matrix: [[8. +7.j 5. +6.j]  [9.+10.j 1. +2.j]] Product of first and second matrices are: (193-11j)

Time complexity: O(n^2), where n is the dimension of the matrices.
Auxiliary space: O(1), as the matrices and their product are stored in memory and no additional space is used.


Next Article
Multiply matrices of complex numbers using NumPy in Python

H

hupphurr
Improve
Article Tags :
  • Python
  • Python-numpy
  • Python numpy-Matrix Function
Practice Tags :
  • python

Similar Reads

    How to plot a complex number in Python using Matplotlib ?
    In this article we will learn how to plot complex number in Python using Matplotlib. Let's discuss some concepts : Matplotlib : Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designe
    3 min read
    Multiplication of two Matrices in Single line using Numpy in Python
    Matrix multiplication is an operation that takes two matrices as input and produces single matrix by multiplying rows of the first matrix to the column of the second matrix.In matrix multiplication make sure that the number of columns of the first matrix should be equal to the number of rows of the
    3 min read
    Compute the condition number of a given matrix using NumPy
    In this article, we will use the cond() function of the NumPy package to calculate the condition number of a given matrix. cond() is a function of linear algebra module in NumPy package. Syntax:  numpy.linalg.cond(x, p=None) Example 1: Condition Number of 2X2 matrix Python3 # Importing library impor
    2 min read
    Python program for multiplication and division of complex number
    Given two complex numbers. The task is to multiply and divide them. Multiplication of complex number: In Python complex numbers can be multiplied using * operator Examples: Input: 2+3i, 4+5i Output: Multiplication is : (-7+22j) Input: 2+3i, 1+2i Output: Multiplication is : (-4+7j) Python3 # Python p
    3 min read
    Compute the determinant of a given square array using NumPy in Python
    In Python, the determinant of a square array can be easily calculated using the NumPy package. This package is used to perform mathematical calculations on single and multi-dimensional arrays. numpy.linalg is an important module of NumPy package which is used for linear algebra. We can use det() fun
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences