# Data Science

## numpy.delete: How to Remove Elements from a NumPy Array

To remove an element from a NumPy array: Specify the index of the element to remove. Call the numpy.delete() function on the array for the given index. For example: Output: This is the quick answer. However, there is a lot more when it comes to removing elements from a NumPy array. In this guide, you …

## numpy.append(): How to Add Elements to a NumPy Array

A NumPy array does not have a built-in append method. Instead, to append elements to a NumPy array, use a separate numpy.append() function. For example: Output: Notice how numpy.append() creates a new copy of the original array. It does not directly append values to it. In this guide, you learn: How appending NumPy arrays work. …

## NumPy How to Create an Empty Array

To create an empty NumPy array: Specify the shape of the array. Call the numpy.empty() function. For instance, let’s create an empty array with no elements: Output: However, creating an array without elements rarely makes any sense. Instead, you should know and specify the shape of the final array in advance. For instance, let’s create …

## NumPy reshape(-1) Meaning

In NumPy, -1 in reshape(-1) refers to an unknown dimension that the reshape() function calculates for you. It is like saying: “I will leave this dimension for the reshape() function to determine”. A common use case is to flatten a nested array of an unknown number of elements to a 1D array. For example: But …

## NumPy @ Operator: Matrix Multiplication in Python

In NumPy, the @ operator means matrix multiplication. For instance, let’s multiply two NumPy arrays that represent 2 x 2 matrices: Output: If you are familiar with matrix multiplication, I’m sure this answers your questions. However, if you do not know what matrix multiplication means, or if you are interested in how the @ operator …

## NumPy How to Transpose a Matrix

To transpose a matrix with NumPy, call the transpose() method. For instance: Output: If you are in a hurry, I’m sure this quick answer is enough. To learn more about matrix transpose, keep on reading. What Is the Transpose of a Matrix The transpose of a matrix is another matrix where the matrix is flipped …

## NumPy How to Concatenate Two Arrays

To concatenate two arrays with NumPy: Import numpy. Put two arrays in a list. Call numpy.concatenate() on the list of arrays. For instance: Output: This is a quick answer. To learn more ways to concatenate arrays and about their efficiency, please, stick around. 4 Ways to Concatenate 1D NumPy Arrays There are four built-in ways …

## NumPy How to Compare Two Arrays

To check if two NumPy arrays A and B are equal: Use a comparison operator (==) to form a comparison array. Check if all the elements in the comparison array are True. For example: This is the easiest approach to comparing two arrays. But this approach is not 100% reliable. Instead, you should consider using …

## How to Manipulate and Clean Data With Python

Data manipulation is an integral part of data preparation. This is especially so since data collection leaves room for duplication and data omission. There are various ways and coding languages for cleaning and manipulating data, but Python is arguably one of the best languages for this. Cleaning and manipulation of data ensure that the data …