Save Plot as Image with Matplotlib

Introduction Matplotlib is one of the most widely used data visualization libraries in Python. It’s common to share Matplotlib plots and visualizations with others. In this article, we’ll take a look at how to save a plot/graph as an image file using Matplotlib. Creating a Plot Let’s first create a simple plot: import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 10, 0.1) y = np.sin(x) plt.plot(x, y) plt.show() Here, we’ve plotted a sine function, starting at 0 […]

Read more

Machine Translation Weekly 44: Tangled up in BLEU (and not blue)

For quite a while, machine translation is approached as a behaviorist simulation. Don’t you know what a good translation is? It does not matter, you can just simulate what humans do. Don’t you know how to measure if something is a good translation? It does not matter, you can simulate what humans do again. Things seem easy. We learn how to translate from tons of training data that were translated by humans. When we want to measure how well the […]

Read more

Machine Translation Weekly 45: Deep Encoder, Shallow Decoder, and the Fall of Non-autoregressive models

Researchers concerned with machine translation speed invented several methods that are supposed to significantly speed up the translation while maintaining as much as possible from the translation quality of the state-of-the-art models. The methods are usually based on generating as many words as possible in parallel. State-of-the-art models do not generate in parallel, they are autoregressive: it means that they generate words one by one and condition the decisions about the next words on the previously generated words. On the […]

Read more

Python with Pandas: DataFrame Tutorial with Examples

Introduction Pandas is an open-source Python library for data analysis. It is designed for efficient and intuitive handling and processing of structured data. The two main data structures in Pandas are Series and DataFrame. Series are essentially one-dimensional labeled arrays of any type of data, while DataFrames are two-dimensional, with potentially heterogenous data types, labeled arrays of any type of data. Heterogenous means that not all “rows” need to be of equal size. In this article we will go through […]

Read more

Remove Element from an Array in Python

Introduction This tutorial will go through some common ways for removing elements from Python arrays. Here’s a list of all the techniques and methods we’ll cover in this article: Arrays in Python Arrays and lists are not the same thing in Python. Although lists are more commonly used than arrays, the latter still have their use cases. The main difference between the two is that lists can be used to store arbitrary values. They are also heterogeneous which means they […]

Read more

Guide to String Interning in Python

Introduction One of the first things you encounter while learning the basics of programming is the concept of strings. Similar to various programming languages, Python strings are arrays of bytes representing Unicode characters – an array or sequence of characters. Python, unlike many programming languages, doesn’t have a distinct character datatype, and characters are considered strings of length 1. You can define a string using single or double quotation marks, for example, a = “Hello World” or a = ‘Hello […]

Read more

Python: Check if Variable is a Number

Introduction In this article, we’ll be going through a few examples of how to check if a variable is a number in Python. Python is dynamically typed. There is no need to declare a variable type, while instantiating it – the interpreter infers the type at runtime: variable = 4 another_variable = ‘hello’ Additionally, a variable can be reassigned to a new type at any given time: # Assign a numeric value variable = 4 # Reassign a string value […]

Read more

Python: Check if File or Directory is Empty

Introduction Python has a set of built-in library objects and functions to help us with this task. In this tutorial, we’ll learn how to check if a file or directory is empty in Python. Distinguish Between a File and a Directory When we’d like to check if a path is empty or not, we’ll want to know if it’s a file or directory since this affects the approach we’ll want to use. Let’s say we have two placeholder variables dirpath […]

Read more

Kernel Density Estimation in Python Using Scikit-Learn

Introduction This article is an introduction to kernel density estimation using Python’s machine learning library scikit-learn. Kernel density estimation (KDE) is a non-parametric method for estimating the probability density function of a given random variable. It is also referred to by its traditional name, the Parzen-Rosenblatt Window method, after its discoverers. Given a sample of independent, identically distributed (i.i.d) observations ((x_1,x_2,ldots,x_n)) of a random variable from an unknown source distribution, the kernel density estimate, is given by: $$p(x) = frac{1}{nh} […]

Read more

Replace Occurrences of a Substring in String with Python

Introduction Replacing all or n occurrences of a substring in a given string is a fairly common problem of string manipulation and text processing in general. Luckily, most of these tasks are made easy in Python by its vast array of built-in functions, including this one. Let’s say, we have a string that contains the following sentence: The brown-eyed man drives a brown car. Our goal is to replace the word “brown” with the word “blue”: The blue-eyed man drives […]

Read more
1 751 752 753 754 755 906