Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How does modulus work with complex numbers in Python?
Floor and modulus operators (// and % respectively) are not allowed to be used on complex number in Python 3.x. However, these operations are defined for complex numbers in Python 2.7.x
Python 3
>>> x=9+2j >>> y=2+1j >>> x%y Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> x%y TypeError: can't mod complex numbers.
Python 2.7
>>> x=9+2j >>> y=2+1j >>> x%y (1-2j)
Modulus of complex number operands returns their floor division multiplied by denominator
>>> x-(x//y)*y (1-2j)
Advertisements
