Tag: NumPy
np.delete(): Remove items/rows/columns from Numpy Array
In this article, we will discuss how to remove elements from a 1D or 2D Numpy Array by index position using numpy.delete(). Then we will also see how to remove rows and columns from 2D numpy array. Delete elements / rows / columns from Numpy Array using np.delete() Table of Contents np.delete() – Overview Delete …
np.delete(): Remove items/rows/columns from Numpy ArrayRead More
How to get Numpy Array Dimensions using numpy.ndarray.shape & numpy.ndarray.size() in Python
In this article we will discuss how to count number of elements in a 1D, 2D & 3D Numpy array, also how to count number of rows & columns of a 2D numpy array and number of elements per axis in 3D numpy array. Get the Dimensions of a Numpy array using ndarray.shape() numpy.ndarray.shape Python’s …
Delete elements from a Numpy Array by value or conditions in Python
In this article we will discuss different ways to delete elements from a Numpy Array by matching value or based on multiple conditions. Remove all occurrences of an element with given value from numpy array Suppose we have a numpy array of numbers i.e. Advertisements # Create a numpy array from a list arr = …
Delete elements from a Numpy Array by value or conditions in PythonRead More
Sorting 2D Numpy Array by column or row in Python
In this article we will discuss how to sort a 2D Numpy array by single or multiple rows or columns. Sorting 2D Numpy Array by a column First of all import numpy module i.e. Advertisements import numpy as np Now suppose we have a 2D Numpy array i.e. # Create a 2D Numpy array list …
How to Reverse a 1D & 2D numpy array using np.flip() and [] operator in Python
In this article we will discuss different ways to reverse the contents of 1D and 2D numpy array ( columns & rows ) using np.flip() and [] operator. Reverse 1D Numpy array using [] operator trick First of all import numpy module i.e. Advertisements import numpy as np Now suppose we have a numpy array …
How to Reverse a 1D & 2D numpy array using np.flip() and [] operator in PythonRead More
How to save Numpy Array to a CSV File using numpy.savetxt() in Python
In this article we will discuss how to save 1D & 2D Numpy arrays in a CSV file with or without header and footer. numpy.savetxt() Python’s Numpy module provides a function to save numpy array to a txt file with custom delimiters and other custom options i.e. Advertisements numpy.savetxt(fname, arr, fmt=’%.18e’, delimiter=’ ‘, newline=’n’, header=”, …
How to save Numpy Array to a CSV File using numpy.savetxt() in PythonRead More
What is a Structured Numpy Array and how to create and sort it in Python?
In this article we will discuss what is a structured numpy array and how to create it and sort it using different functions. What is a Structured Numpy Array ? A Structured Numpy Array is an array of structures (Similar to C struct). As numpy arrays are homogeneous i.e. they can contain data of same …
What is a Structured Numpy Array and how to create and sort it in Python?Read More
How to sort a Numpy Array in Python ?
In this article we will discuss different ways to sort a numpy array in python. Python’s Numpy module provides 2 different methods to sort a numpy array. numpy.ndarray.sort() A member function of ndarray class, Advertisements ndarray.sort(axis=-1, kind=’quicksort’, order=None) It can be called through a numpy array object (ndarray) and it sorts the associated numpy array …
Create an empty Numpy Array of given length or shape & data type in Python
In this article we will discuss different ways to create an empty 1D,2D or 3D Numpy array and of different data types like int or string etc. Python’s numpy module provides a function empty() to create new arrays, Advertisements numpy.empty(shape, dtype=float, order=’C’) It accepts shape and data type as arguments. Returns a new array of …
Create an empty Numpy Array of given length or shape & data type in PythonRead More
Python : Create boolean Numpy array with all True or all False or random boolean values
In this article we will discuss different ways to create a boolean Numpy array. We will start by creating Numpy arrays with random boolean values. Then we will see ways to create a Numpy array with all True or all False. Create boolean Numpy array with random boolean values To create a boolean numpy array …
Python : Create boolean Numpy array with all True or all False or random boolean valuesRead More