Data Science

How to Compare Each Element of a Numpy Array Against a Value?

To compare each element of a NumPy array arr against the scalar x using any of the greater (>), greater equal (>=), smaller (<), smaller equal (<=), or equal (==) operators, use the broadcasting feature with the array as one operand and the scalar as another operand. For example, the greater comparison arr > x …

How to Compare Each Element of a Numpy Array Against a Value? Read More »

How to Create a Dictionary From Two NumPy Arrays?

Anyone working with lists of data will encounter a need to combine them in a useful way. Often the best result is a dictionary consisting of keys and values. In this article, you’ll learn how to create a dictionary from two NumPy arrays. Problem Formulation: Given two NumPy arrays a and b. Create a dictionary …

How to Create a Dictionary From Two NumPy Arrays? Read More »

How to Create a Sequence of Linearly Increasing Values with Numpy Arange?

Problem: How to create a sequence of linearly increasing values? Solution: Use NumPy’s arange() function. The np.arange([start,] stop[, step]) function creates a new NumPy array with evenly-spaced integers between start (inclusive) and stop (exclusive). The step size defines the difference between subsequent values. For example, np.arange(1, 6, 2) creates the NumPy array [1, 3, 5]. …

How to Create a Sequence of Linearly Increasing Values with Numpy Arange? Read More »

How to Initialize a NumPy Array with Zeros and Ones

Numpy is a popular Python library for data science focusing on linear algebra. In this article, you’ll learn how to initialize your NumPy array. How to Initialize a NumPy Array with Zeros? To initialize your NumPy array with zeros, use the function np.zeros(shape) where shape is a tuple that defines the shape of your desired …

How to Initialize a NumPy Array with Zeros and Ones Read More »

Matplotlib Cursor — How to Add a Cursor and Annotate Your Plot

This article explains how to insert a cursor to your plot, how to customize it and how to store the values that you selected on the plot window. In lots of situations we may want to select and store the coordinates of specific points in our graph; is it just for assessing their value or …

Matplotlib Cursor — How to Add a Cursor and Annotate Your Plot Read More »

Proportional Sampling Using Weighted Values

Probability and Statistics play a very important role in the field of data science and machine learning. In this blog post you will learn the concept of proportional sampling and how can we implement it from scratch without using any library Proportional Sampling Let us take an example of tossing a die to better understand …

Proportional Sampling Using Weighted Values Read More »

How to Sort in Python with the Lambda Function as Key Argument?

Challenge: This article shows how to sort a Python list using the key argument that takes a function object as an argument. Quick Solution: You can use the lambda function to create the function on the fly as shown in the following example: Explanation: The code uses the key argument and passes a lambda function …

How to Sort in Python with the Lambda Function as Key Argument? Read More »

Matplotlib Widgets — How to Make Your Plot Interactive With Buttons

This article presents different types of widgets that can be embedded within a matplotlib figure, in order to create and personalize highly interactive plots. Exploiting the matplotlib package .widget(), it is hence possible to create personalized buttons that allows controlling different properties of the graphs that are plotted in the main window. This represents a …

Matplotlib Widgets — How to Make Your Plot Interactive With Buttons Read More »

[Collection] 10 Tensorflow Cheat Sheets Every ML Engineer Must Download, Print, and Study

Have a little time to learn Tensorflow 2.0 with your Machine Learning? In this article, I have put together the 10 best Tensorflow cheat sheets for you to hang on the wall above your desk. Whenever you need a reference, keep these handy cheat sheets available!! Cheat Sheet 1: BecomingHuman.AI becominghuman.ai has multiple cheat sheets …

[Collection] 10 Tensorflow Cheat Sheets Every ML Engineer Must Download, Print, and Study Read More »