by Suf | Feb 4, 2022 | Programming, Python, Tips
If you try to evaluate a numpy array in the Boolean context, you will raise the error: Python ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). To solve this error, you can use the built-in any() and all()...
by Suf | Feb 4, 2022 | Programming, Python, Tips
Matrix multiplication is a binary operation that produces a matrix from two matrices. Multiplying matrices is ubiquitous in mathematics, physics and computer science. You can perform matrix multiplication in Python using nested loops, list comprehension or the dot()...
by Suf | Feb 2, 2022 | Programming, Python, Tips
If you pass an empty list to the bool() function, it will return False. An empty list in an if statement will also return False. If you pass an empty list to the len() function, it will return 0. In this tutorial, we will go through several methods to check if a list...
by Suf | Feb 1, 2022 | Programming, Python, Tips
The factorial of a positive integer n is the multiplication operation of all integers smaller than or equal to n. The notation of the factorial is the exclamation mark, n!. For example, the factorial of 5 is: 5! = 5 * 4 * 3 * 2 * 1 = 120 This tutorial will go through...
by Suf | Jan 31, 2022 | DSA, Python, Tips
Introduction The Fibonacci sequence is a fascinating mathematical series where each number is the sum of the two preceding ones. Let’s explore different ways to implement this sequence in Python, comparing their efficiency and use cases. Table of Contents...
by Suf | Jan 30, 2022 | Programming, Python, Tips
This tutorial will go through how to get the union of sets in Python with the help of some code examples. Table of contentsWhat is a Set?What is Set Union?Using the Union MethodUsing the OR Operator |Summary What is a Set? A Python set is one of the four built-in data...