How to Compress PDF Files Using Python?

Problem Formulation Suppose you have a PDF file, but it’s too large and you’d like to compress it (perhaps you want to reduce its size to allow for faster transfer over the internet, or perhaps to save storage space).  Even more challenging, suppose you have multiple PDF files you’d like to compress.  Multiple online options … Read more

PyTorch Developer – Income and Opportunity

Before we learn about the money, let’s get this question out of the way: What Is PyTorch? Let’s have a look at the definition from the official PyTorch website: “An open source machine learning framework that accelerates the path from research prototyping to production deployment. More specifically, PyTorch is an optimized tensor library for deep … Read more

How to Swap List Elements in Python?

Problem Formulation Given a list of size n and two indices i,j < n. Swap the element at index i with the element at index j, so that the element list[i] is now at position j and the original element list[j] is now at position i. Examples: Swapping indices 0 and 2 in list [1, … Read more

np.reshape() — The Ultimate Guide in Python

Most of the function names in Python can be intuitively connected to the meaning of the function. The NumPy reshape() function is not an exception. The reshape() function brings an array into another shape while keeping all the original data. I’ll demonstrate a couple of simple examples in the following video guide: To summarize how … Read more

Build Website with Flask – Part 5

This is part of our Flask series: Build Website with Flask – Part 1 Build Website with Flask – Part 2 Build Website with Flask – Part 3 Build Website with Flask – Part 4 Build Website with Flask – Part 5 Build Website with Flask – Part 6 Build Website with Flask – Part … Read more

Build Website with Flask – Part 4

This is part of our Flask series: Build Website with Flask – Part 1 Build Website with Flask – Part 2 Build Website with Flask – Part 3 Build Website with Flask – Part 4 Build Website with Flask – Part 5 Build Website with Flask – Part 6 Build Website with Flask – Part … Read more

How to Fix “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()”

Here’s an error I recently encountered when working with NumPy arrays: If you run the following code, you’ll experience a special ValueError: The output will be this error message: How can you fix this error? I’ll give you a short and a long answer to this question. Let’s start with the short one: Solution: Use … Read more

Python Map to Int

Problem Formulation Convert a string list to an integer list using the map() function. Example: Input: [‘1’, ‘2’, ‘3’] Output: [1, 2, 3] Input: [’42’] Output: [42] Input: [‘-1’, ‘-2’, ‘-3’] Output: [-1, -2, -3] Solution Using Map To convert a list of strings to a list of integers, you can “map to int” by … Read more

Python os.walk() – A Simple Illustrated Guide

According to the Python version 3.10.3 official doc, the os module provides built-in miscellaneous operating system interfaces. We can achieve many operating system dependent functionalities through it. One of the functionalities is to generate the file names in a directory tree through os.walk(). If it sounds great to you, please continue reading, and you will … Read more