Explain ifelse condition in theano.

This recipe explains what ifelse condition in theano.

Recipe Objective - Explain if-else condition in theano.

IfElse takes a boolean condition and two variables as inputs.
Syntax: ifelse(condition, resultIFtrue, resultIFfalse)

For more related projects -

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

Example -
Let's create a function which will return the minimum number among two using ifelse condition in theano:

# Importing libraries
import theano
from theano import tensor
from theano.ifelse import ifelse

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

# if - else expression
ifelse_expression = ifelse(tensor.lt(x, y), x, y)

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

# Calling function
fun(12,11)

Output -
array(11.)

In this way, we can make use of the if-else condition in theano.

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

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

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Build a CNN Model with PyTorch for Image Classification
In this deep learning project, you will learn how to build an Image Classification Model using PyTorch CNN

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.