
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Make a grid for computing a Mandelbrot set with outer product in Python
Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product [1] is −
[[a0*b0 a0*b1 ... a0*bN ] [a1*b0 . [ ... . [aM*b0 aM*bN ]]
To get the Outer product of two arrays, use the numpy.outer() method in Python. The numpy.ones() return a new array of given shape and type, filled with ones. The numpy.linspace() returns evenly spaced numbers over a specified interval.
Steps
At first, import the required libraries −
import numpy as np
The real part −
rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5)) print("The real part of the complex number...\n",rl)
The imaginary part −
im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,))) print("\nThe imaginary part of the complex numbers...\n",rl)
Forming a grid −
grid = rl + im
Example
import numpy as np # To get the Outer product of two arrays, use the numpy.outer() method in Python # The numpy.ones() return a new array of given shape and type, filled with ones. # The numpy.linspace() returns evenly spaced numbers over a specified interval. # The real part rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5)) print("The real part of the complex number...\n",rl) # The imaginary part im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,))) print("\nThe imaginary part of the complex numbers...\n",rl) # Forming a grid grid = rl + im print("\nDisplaying the grid...\n",grid)
Output
The real part of the complex number... [[-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.]] The imaginary part of the complex numbers... [[-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.] [-2. -1. 0. 1. 2.]] Displaying the grid... [[-2.+2.j -1.+2.j 0.+2.j 1.+2.j 2.+2.j] [-2.+1.j -1.+1.j 0.+1.j 1.+1.j 2.+1.j] [-2.+0.j -1.+0.j 0.+0.j 1.+0.j 2.+0.j] [-2.-1.j -1.-1.j 0.-1.j 1.-1.j 2.-1.j] [-2.-2.j -1.-2.j 0.-2.j 1.-2.j 2.-2.j]]
- Related Articles
- Vector outer product with Einstein summation convention in Python
- Grid Computing
- Set a default row size for CSS Grid
- Get the Outer product of an array and a scalar in Python
- Difference between Cluster Computing and Grid Computing
- Difference between Cloud Computing and Grid Computing
- Get the Outer Product of an array with vector of letters in Python
- Get the Outer product of two arrays in Python
- Get the Outer product of two multidimensional arrays in Python
- Get the Outer product of two One-Dimensional arrays in Python
- How to make a grid of images in PyTorch?
- C++ Program to find out the total cost required for a robot to make a trip in a grid
- Python Helpers for Computing Deltas
- Set the name to Grid Items with CSS
- Return the outer product of two masked arrays with different shapes in Numpy

Advertisements