Generate a generic 2D Gaussian like array?

Generate a generic 2D Gaussian like array?

Generate a generic 2D Gaussian like array?

Generate a generic 2D Gaussian like array


Recipe Objective

2D Gaussian distribution is very similar to a normal function but in place of x we use square-roots of squares of 1D variables.

So this recipe is a short example on how to generate a generic 2D Gaussian-like array. Let's get started.

Step 1 - Import the library

import numpy as np

Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.

Step 2 - Generating a 2D gaussian array

x, y = np.meshgrid(np.linspace(-1,1,10), np.linspace(-1,1,10)) d = np.sqrt(x*x+y*y) sigma, mu = 1.0, 0.0 g = np.exp(-( (d-mu)**2 / ( 2.0 * sigma**2 ) ) )

Let's have a loop at each step one by one. One first step, we have created two, 2D arrays, using meshgrid and linespace function. Meshgrid basically creates a rectangular grid out of two given one-dimensional array. Linespace returns number spaces evenly w.r.t interval. In 2nd step, we are calculating the square-roots of squares of s and y. Finally, using exp function, we are genearating the guassian array.

Step 3 - Printing Output


Simply using print function, we have print our gaussian array.

Step 4 - Lets look at our dataset now

Once we run the above code snippet, we will see:

Scroll down to the ipython file below to visualize the output.

Relevant Projects

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Census Income Data Set Project - Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based on census data.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.