How to create a tensor with normal distribution using tf

This recipe helps you create a tensor with normal distribution using tf

Recipe Objective

How to create a tensor with normal distribution using tf?

Normal Distribution it is a distribution where the data is being normally distributed which is also called Gaussian Distribution. The curve in distribution is called a bell curve. In this both mean and median are equal both are located at the center of the distribution. In case of standard deviation: 1st standard deviation - 68% data falls in. 2nd standard deviation - 95% data falls in. 3rd standard deviation - 99.7% data falls in. In TensorFlow, this is achieved by using "tf.random.normal" which gives the output of random values from a normal distribution.

Step 1 - Import library

import tensorflow as tf

Step 2 - Perform the distribution

normal_1 = tf.random.normal([5], 1, 2, tf.float32) normal_2 = tf.random.normal([3,3], 1, 2, tf.float32)

Step 3 - Print Results

print("This is normal distribution for first value:", normal_1, "\n") print("This is normal distribution for second value:", normal_2)

This is normal distribution for first value: tf.Tensor([-2.9598637  1.7986646  1.5461733  3.7152798  2.717798 ], shape=(5,), dtype=float32) 

This is normal distribution for second value: tf.Tensor(
[[ 0.42061305  2.0601416   2.2169108 ]
 [-1.1691282   1.5044242   1.4621482 ]
 [ 3.3253074   0.92909837  0.55594873]], shape=(3, 3), dtype=float32)

{"mode":"full","isActive":false}

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Image Segmentation using Mask R-CNN with Tensorflow
In this Deep Learning Project on Image Segmentation Python, you will learn how to implement the Mask R-CNN model for early fire detection.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.

Learn to Build an End-to-End Machine Learning Pipeline - Part 2
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, incorporating Hopsworks' feature store and Weights and Biases for model experimentation.

Multilabel Classification Project for Predicting Shipment Modes
Multilabel Classification Project to build a machine learning model that predicts the appropriate mode of transport for each shipment, using a transport dataset with 2000 unique products. The project explores and compares four different approaches to multilabel classification, including naive independent models, classifier chains, natively multilabel models, and multilabel to multiclass approaches.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

Learn to Build a Neural network from Scratch using NumPy
In this deep learning project, you will learn to build a neural network from scratch using NumPy