Python tutorials

What Are Python Raw Strings?

If you’ve ever come across a standard string literal prefixed with either the lowercase letter r or the uppercase letter R, then you’ve encountered a Python raw string: Although a raw string looks and behaves mostly the same as a normal string literal, there’s an important difference in how Python interprets some of its characters, which you’ll explore in this tutorial. Notice that there’s nothing special about the resulting string object. Whether you declare your literal value using a prefix […]

Read more

Python Basics: Lists and Tuples

Python lists are similar to real-life lists. You can use them to store and organize a collection of objects, which can be of any data type. Instead of just storing one item, a list can hold multiple items while allowing manipulation and retrieval of those items. Because lists are mutable, you can think of them as being written in pencil. In other words, you can make changes. Tuples, on the other hand, are written in ink. They’re similar to lists […]

Read more

When to Use a List Comprehension in Python

One of Python’s most distinctive features is the list comprehension, which you can use to create powerful functionality within a single line of code. However, many developers struggle to fully leverage the more advanced features of list comprehensions in Python. Some programmers even use them too much, which can lead to code that’s less efficient and harder to read. By the end of this tutorial, you’ll understand the full power of Python list comprehensions and know how to use their […]

Read more

Beware of misleading GPU vs CPU benchmarks

Do you use NumPy, Pandas, or scikit-learn and want to get faster results? Nvidia has created GPU-based replacements for each of these with the shared promise of extra speed. For example, if you visit the front page of NVidia’s RAPIDS project, you’ll see benchmarks showing cuDF, a GPU-based Pandas replacement, is 15× to 80× faster than Pandas! Unfortunately, while those speed-ups are impressive, they are also misleading. GPU-based libraries might be the answer to your performance problems… or they might […]

Read more

Q-learning for beginners

The goal of this article is to teach an AI how to solve the ❄️Frozen Lake environment using reinforcement learning. We’re going to start from scratch and try to recreate the Q-learning algorithm by ourselves. We’ll not just understand how it works, but more importantly, why it was designed that way. By the end of this article, you’ll master the Q-learning algorithm and be able to apply it to other environments. It’s a cool mini-project that gives a better insight […]

Read more

Introduction to Linear Programming in Python

Linear programming is a technique to optimize any problem with multiple variables and constraints. It’s a simple but powerful tool every data scientist should master. Imagine you are a strategist recruiting an army. You have: Three resources: 🌾food, 🪵wood, and 🪙gold Three units: 🗡️swordsmen, 🏹bowmen, and 🐎horsemen. Horsemen are stronger than bowmen, who are in turn stronger than swordsmen. The following table provides the cost and power of each unit: 🗡️Swordsman 60 20 0 70 🏹Bowman 80 10 40 95 […]

Read more

Integer vs. Linear Programming in Python

Why is linear programming called that way? Both terms are confusing: Linear implies that nonlinear programming exists; Programming actually means “planning” in this context. In summary, it has nothing to do with code: linear or not. It’s about optimizing variables with various constraints. In this article, we’re gonna talk about another type of optimization: integer programming. We’ll see why a good understanding of the problem we face is necessary to choose the right solver. Finally, we will write a model […]

Read more

Graph Attention Networks: Self-Attention for GNNs

Graph Attention Networks (GATs) are one of the most popular types of Graph Neural Networks. Instead of calculating static weights based on node degrees like Graph Convolutional Networks (GCNs), they assign dynamic weights to node features through a process called self-attention. The main idea behind GATs is that some neighbors are more important than others, regardless of their node degrees. Node 4 is more important than node 3, which is more important than node 2 In this article, we will […]

Read more
1 3 4 5 6 7 164