Tag: NumPy
Create an empty 2D Numpy Array / matrix and append rows or columns in python
In this article we will discuss how to create an empty matrix or 2D numpy array first using numpy.empty() and then append individual rows or columns to this matrix using numpy.append(). Before moving forward, let’s have a quick look at the two functions which we are going to use in this article, Advertisements numpy.empty() numpy.empty(shape, …
Create an empty 2D Numpy Array / matrix and append rows or columns in pythonRead More
6 Ways to check if all values in Numpy Array are zero (in both 1D & 2D arrays) – Python
In this article we will discuss seven different ways to check if all values in a numpy array are 0. Then we will look how to find rows or columns with only zeros in a 2D array or matrix. Check if all values in a 1D Numpy Array are Zero First of all, we will …
6 Ways to check if all values in Numpy Array are zero (in both 1D & 2D arrays) – PythonRead More
Python: Check if all values are same in a Numpy Array (both 1D and 2D)
In this article we will discuss different ways to check if all values in a 1D or 2D numpy array are equal. Then we will see how to find rows or columns with the same values in a 2D array or matrix. Check if all elements are equal in a 1D Numpy Array using numpy.all() …
Python: Check if all values are same in a Numpy Array (both 1D and 2D)Read More
Python: Convert Matrix / 2D Numpy Array to a 1D Numpy Array
In this article we will discuss different ways to convert a 2D numpy array or Matrix to a 1D Numpy Array. First, import the numpy module, Advertisements import numpy as np Convert 2D Numpy array / Matrix to a 1D Numpy array using flatten() Python’s Numpy module provides a member function in ndarray to flatten …
Python: Convert Matrix / 2D Numpy Array to a 1D Numpy ArrayRead More
Python: Convert a 1D array to a 2D Numpy array or Matrix
In this article we will discuss how to convert a 1D Numpy Array to a 2D numpy array or Matrix using reshape() function. We will also discuss how to construct the 2D array row wise and column wise, from a 1D array. Suppose we have a 1D numpy array of size 10, Advertisements # create …
Python: Convert a 1D array to a 2D Numpy array or MatrixRead More
Python Numpy: flatten() vs ravel()
In this article we will discuss main differences between numpy.ravel() and ndarray.flatten() functions. Objective of both the numpy.ravel() and ndarray.flatten() functions is the same i.e. flatten a numpy array of any shape. But there are some basic differences in both of them. Before going into detail about differences, let’s have a basic overview of both …
np.zeros() – Create Numpy Arrays of zeros (0s)
In this article, we will discuss how to create 1D or 2D numpy arrays filled with zeros (0s). np.zeros() – Create Numpy Arrays of zeros (0’s) numpy.zeros() Python’s Numpy module provides a function to create a numpy array of given shape & type and filled with 0’s i.e, numpy.zeros(shape, dtype=float, order=’C’) Arguments: Advertisements shape: Shape …
np.ones() – Create 1D / 2D Numpy Array filled with ones (1’s)
In this article, we will discuss how to create 1D or 2D numpy arrays filled with ones (1s). np.ones() – Create 1D / 2D Numpy Array filled with ones (1’s) numpy.ones() Python’s Numpy module provides a function to create a numpy array of given shape & type and filled with 1’s i.e, numpy.ones(shape, dtype=float, order=’C’) …
np.ones() – Create 1D / 2D Numpy Array filled with ones (1’s)Read More
Convert NumPy array to list in python
In this article we will discuss how to convert a 1D or 2D or 3D Numpy Array to a list or list of lists. Table of Contents Convert a Numpy Array to a List Convert 2D Numpy array to list of lists Convert 2D Numpy array to a flat list Convert 3D Numpy array to …
Convert 2D NumPy array to list of lists in python
In this article, we will learn how to convert 2D Numpy Array to a nested list i.e. list of lists. Convert 2D Numpy Array to list of lists using tolist() In Python’s numpy module, the ndarray class provides a member function tolist(), which returns a list containing the copy of elements in the numpy array. …