Arithmetic and Logical Operators
Explore how to use arithmetic and logical operators in Python compared to MATLAB. Understand matrix transposition, rounding functions, and comparison operations. This lesson helps you apply these concepts using Python libraries like NumPy to replicate MATLAB functionality.
Arithmetic operators
The table below compares the arithmetic operators of MATLAB and Python.
Operators | MATLAB | Python |
Addition |
|
|
Subtraction |
|
|
Multiplication |
|
|
Division |
|
|
Power |
|
|
Modulo |
|
|
Quotient |
|
|
Rounding |
|
|
Greater than, greater than or equal to |
|
|
Less than, less than or equal to |
|
|
Equal to |
|
|
Not equal to |
|
|
Due to the large collection of Python libraries, we can implement almost all MATLAB operators in Python. Let’s look at a few examples.
Multiplication, division, and power operators
MATLAB has several operators for performing multiplication, division, and power operations on arrays. The . operator performs the element-wise operations, For example:
The table below shows how the above MATLAB operations can be performed in Python using NumPy ...