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

3 Examples of Monte Carlo Simulation in Python

Introduction In this post, we will understand what is Monte Carlo Simulation, what are its typical steps along with benefits and limitations. We will also take a look at its real-world application followed by a few examples of Monte Carlo simulation in Python along with visualization for better clarity. What is Monte Carlo Simulation Monte Carlo simulation is a computational technique to approximate the behavior or output of a complex system or problem by repeated random sampling. This method relies […]

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

Techniques to Write Better Python Code

We write a program to solve a problem or make a tool that we can repeatedly solve a similar problem. For the latter, it is inevitable that we come back to revisit the program we wrote, or someone else is reusing the program we write. There is also a chance that we will encounter data that we didn’t foresee at the time we wrote our program. After all, we still want our program to work. There are some techniques and […]

Read more

Using Kaggle in Machine Learning Projects

You’ve probably heard of Kaggle data science competitions, but did you know that Kaggle has many other features that can help you with your next machine learning project? For people looking for datasets for their next machine learning project, Kaggle allows you to access public datasets by others and share your own datasets. For those looking to build and train their own machine learning models, Kaggle also offers an in-browser notebook environment and some free GPU hours. You can also […]

Read more

Setting Breakpoints and Exception Hooks in Python

There are different ways of debugging code in Python, one of which is to introduce breakpoints into the code at points where one would like to invoke a Python debugger. The statements used to enter a debugging session at different call sites depend on the version of the Python interpreter that one is working with, as we shall see in this tutorial.  In this tutorial, you will discover various ways of setting breakpoints in different versions of Python.  After completing […]

Read more

Static Analyzers in Python

Static analyzers are tools that help you check your code without really running your code. The most basic form of static analyzers is the syntax highlighters in your favorite editors. If you need to compile your code (say, in C++), your compiler, such as LLVM, may also provide some static analyzer functions to warn you about potential issues (e.g., mistaken assignment “=” for equality “==” in C++). In Python, we have some tools to identify potential errors or point out […]

Read more

Profiling Python Code

Profiling is a technique to figure out how time is spent in a program. With these statistics, we can find the “hot spot” of a program and think about ways of improvement. Sometimes, a hot spot in an unexpected location may hint at a bug in the program as well. In this tutorial, we will see how we can use the profiling facility in Python. Specifically, you will see: How we can compare small code fragments using the timeit module […]

Read more
1 59 60 61 62 63 908