What is a symbolic sparse matrix in theano?

This recipe explains what is symbolic sparse matrix in theano.

Recipe Objective - What is a symbolic sparse matrix in theano?

The sparse module is similar to the tensor module in terms of functionality. Because sparse matrices do not hold data in a contiguous array, the difference is hidden under the surface.

Theano has two compressed sparse formats: csc and csr, which are based on columns and rows, respectively. They have the same data, indices, indptr, and form properties.
Attributes:
1. The data attribute is a one-dimensional ndarray that contains all of the sparse matrix's non-zero members.
2. The data position in the sparse matrix is stored using the indices and indptr properties.
3. The shape attribute is the same as the dense matrix's shape attribute.

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects

https://www.projectpro.io/projects/data-science-projects/tensorflow-projects

Compressed Sparse Column (csc) Matrix

In the Compressed Sparse Column (csc) format, indices refers to indexes within the matrix's column vectors, whereas indptr specifies the position of the column in the data and indices attributes.

# Importing libraries
import numpy as np
import scipy.sparse as sci_sp

# Creating 'data' array
data = np.asarray([10, 20, 30])

# Creating 'indices' array
indices = np.asarray([0, 1, 2])

# Creating 'indptr' array
indptr = np.asarray([0, 3, 2, 1])

# Creating csc matrix
matrix = sci_sp.csc_matrix((data, indices, indptr), shape=(3, 3))
matrix.toarray()

Output -
array([[10,  0,  0],
       [20,  0,  0],
       [30,  0,  0]])

Compressed Sparse Row (csr) Matrix

In the Compressed Sparse Row (csr) format, indices refers to indexes within the matrix's row vectors, whereas indptr specifies the position of the row in the data and indices attributes.

# Importing libraries
import numpy as np
import scipy.sparse as sci_sp

# Creating 'data' array
data = np.asarray([10, 20, 30])

# Creating 'indices' array
indices = np.asarray([0, 1, 2])

# Creating 'indptr' array
indptr = np.asarray([0, 3, 2, 1])

# Creating csr matrix
matrix = sci_sp.csr_matrix((data, indices, indptr), shape=(3, 3))
matrix.toarray()

Output -
array([[10, 20, 30],
       [ 0,  0,  0],
       [ 0,  0,  0]])

In this way, we can create a symbolic sparse matrix 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

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

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.

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.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Loan Eligibility Prediction Project using Machine learning on GCP
Loan Eligibility Prediction Project - Use SQL and Python to build a predictive model on GCP to determine whether an application requesting loan is eligible or not.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.