Explain switch condition in theano.

This recipe explains what switch condition in theano.

Recipe Objective - Explain switch condition in theano.

Switch takes a tensor as a condition and two variables as inputs. The switch is an elementwise operation and is thus more general than ifelse.
Syntax: switch(condition, resultIFtrue, resultIFfalse)

For more related projects -

/projects/data-science-projects/keras-deep-learning-projects
/projects/data-science-projects/deep-learning-projects

Example -
Let's create a function that will return the maximum number among two using switch condition in theano:

# Importing libraries
import theano
from theano import tensor

# Creating two scalars
x,y = tensor.scalars('x', 'y')

# switch expression
switch_expression = tensor.switch(tensor.gt(x, y), x, y)

# Creating function
fun = theano.function([x, y], switch_expression, mode=theano.compile.mode.Mode(linker='vm'))

# Calling function fun(12,11)

Output -
array(12.)

In this way, we can make use of the switch condition in theano.

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

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 to Build a Siamese Neural Network for Image Similarity
In this Deep Learning Project, you will learn how to build a siamese neural network with Keras and Tensorflow for Image Similarity.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Build a Hybrid Recommender System in Python using LightFM
In this Recommender System project, you will build a hybrid recommender system in Python using LightFM .

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.