How to SUBTRACT numerical value to each element of a matrix?

How to SUBTRACT numerical value to each element of a matrix?

How to SUBTRACT numerical value to each element of a matrix?

This recipe helps you SUBTRACT numerical value to each element of a matrix

In [1]:
## How to SUBTRACT numerical value to each electment of a matrix
def Kickstarter_Example_16():
    print(format('How to subtract something to each electment of a matrix',

    # Load library
    import numpy as np

    # Create two vectors
    matrixA = np.array([[2, 3, 23],
                       [5, 6, 25],
                       [8, 9, 28]])

    # Create a function that adds 100 to something
    add_100 = lambda i: i - 15

    # Create a vectorized function
    vectorized_add_100 = np.vectorize(add_100)

    # Apply function to all elements in matrix
    print(); print(vectorized_add_100(matrixA))

********How to subtract something to each electment of a matrix*********

[[-13 -12   8]
 [-10  -9  10]
 [ -7  -6  13]]

Relevant Projects

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

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.

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.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.