NumPy
-
Essential Python Libraries: Introduction to NumPy and Pandas
In Python programming, NumPy and Pandas stand out as two of the most powerful libraries for numerical computing and data manipulation. NumPy: The Foundation of Numerical Computing NumPy (Numerical Python) provides support for multi-dimensional arrays and a wide range of mathematical functions, making it essential for scientific computing. NumPy is the most foundational package for numerical computing in Python. One of the reasons why NumPy is so important for numerical computations is that it is designed for efficiency with large…
-
Maximizing the Potential of LLMs: Using Vector Databases
LLMs do Natural Language Processing (NLP) to represent the meaning of the text as a vector. This representation of the words of the text is an embedding. The Token Limit: The LLM Prompting Biggest Problem Currently, one of the biggest problems with LLM prompting is the token limit. When GPT-3 was released, the limit for both the prompt and the output combined was 2,048 tokens. With GPT-3.5, this limit increased to 4,096 tokens. Now, GPT-4 comes in two variants. One…
-
Fix AttributeError: \’NoneType\’ Object Has No Attribute \’Shape\’
NumPy is a popular tool for computing numbers involving matrices, arrays, and math functions. The shape attribute of a NumPy array returns a tuple showing the array’s dimensions. And when it comes to reshaping and manipulating NumPy arrays, the attribute is crucial. Below is how the shape attribute function: Python import numpy as np arr = np.array([[5, 1], [16, 33]]) print(arr.shape) Output: Python (2, 2) The shape attribute is also important in pandas or OpenCV. Here is how…
-
NumPy Matrix transpose() – Transpose of an Array in Python
The transpose of a matrix is obtained by moving the rows data to the column and columns data to the rows. If we have an array of shape (X, Y) then the transpose of the array will have the shape (Y, X). NumPy Matrix transpose() Python numpy module is mostly used to work with arrays in Python. We can use the transpose() function to get the transpose of an array. import numpy as np arr1 = np.array([[1, 2, 3], [4,…
-
How to use Python numpy.where() Method
In Python, we can use the numpy.where() function to select elements from a numpy array, based on a condition. Not only that, but we can perform some operations on those elements if the condition is satisfied. Let’s look at how we can use this function, using some illustrative examples! Syntax of Python numpy.where() This function accepts a numpy-like array (ex. a NumPy array of integers/booleans). It returns a new numpy array, after filtering based on a condition, which is a…
-
Norm of a One-Dimensional Tensor in Python Libraries
The calculation of the norm of vectors is essential in both artificial intelligence and quantum computing for tasks such as feature scaling, regularization, distance metrics, convergence criteria, representing quantum states, ensuring unitarity of operations, error correction, and designing quantum algorithms and circuits. You will learn how to calculate the Euclidean (norm/distance), also known as the L2 norm, of a single-dimensional (1D) tensor in Python libraries like NumPy, SciPy, Scikit-Learn, TensorFlow, and PyTorch. Understand Norm vs Distance Before we begin, let’s…
-
How To Implement Cosine Similarity in Python
Cosine similarity has several real-world applications, and by using embedding vectors, we can compare real-world meanings in a programmatic manner. Python is one of the most popular languages for data science, and it offers various libraries to calculate cosine similarity with ease. In this article, we’ll discuss how you can implement cosine similarity in Python using the help of Scikit-Learn and NumPy libraries. What Is Cosine Similarity? Cosine similarity is a measure of similarity between two non-zero vectors in an…
-
numpy.sum() in Python
Python numpy sum() function is used to get the sum of array elements over a given axis. Python numpy sum() function syntax Python NumPy sum() method syntax is: sum(array, axis, dtype, out, keepdims, initial) The array elements are used to calculate the sum. If the axis is not provided, the sum of all the elements is returned. If the axis is a tuple of ints, the sum of all the elements in the given axes is returned. We can specify…
-
numpy.append() in Python
Python numpy append() function is used to merge two arrays. This function returns a new array and the original array remains unchanged. NumPy append() Syntax The function syntax is: numpy.append(arr, values, axis=None) The arr can be an array-like object or a NumPy array. The values are appended to a copy of this array. The values are array-like objects and it’s appended to the end of the “arr” elements. The axis specifies the axis along which values are appended. If the…