NumPy Arrays on Digital Blackboard
/python/numpyarrays/
Recent content in NumPy Arrays on Digital Blackboard
Hugo  gohugo.io
enus
Copyright © 2022{year} Digital Blackboard. All Rights Reserved.
Sat, 04 Dec 2021 10:43:39 +0800

NumPy Structured Arrays
/python/numpyarrays/structuredarrays/
Sat, 23 Jul 2022 00:00:00 +0000
/python/numpyarrays/structuredarrays/
Table of Contents
Introduction
Creating Structured Arrays
Compound Data Type
Initialization and Printing
Indexing and Slicing
Filtering with numpy.sort
Sorting
Introduction
This section discusses the use of NumPy structured arrays which provide efficient storage for compound, heterogeneous data.
Structured arrays are ndarrays whose datatype is a composition of simpler datatypes organized as a sequence of named fields. The following is an example of a structured array that consists of 3 named fields  “name”, “age” and “weight”.

NumPy Array Search
/python/numpyarrays/arraysearch/
Fri, 22 Jul 2022 00:00:00 +0000
/python/numpyarrays/arraysearch/
Table of Contents
Introduction
The numpy.extract Function
The numpy.where Function
Returning Indices
Returning Modified Array
The numpy.insert Function
The numpy.searchsorted Function
Introduction
You can search an array for a certain value and return either the value or the indices corresponding to the value.
The numpy.extract Function
The numpy.extract function returns the elements of an array that satisfy some condition.
Syntax
The numpy.extract function.
1numpy.extract(condition, arr) Parameter Required? Default Value Description condition ✔️ Yes NA An array whose nonzero or True entries indicate the elements of arr to extract.

NumPy Array Sorting
/python/numpyarrays/arraysorting/
Fri, 22 Jul 2022 00:00:00 +0000
/python/numpyarrays/arraysorting/
Table of Contents
Introduction
The numpy.sort Function
Sorting of 1D arrays
Sorting of 2D arrays
The numpy.ndarray.sort Method
The numpy.argsort Function.
Introduction
Sorting an array means rearranging the elements into an ascending or descending ordered sequence. In this article, we will examine the NumPy function numpy.sort and the related ndarray object method sort().
The numpy.sort Function
The numpy.sort function returns a sorted copy of an array.
Syntax
The numpy.sort function.

NumPy Array Splitting
/python/numpyarrays/arraysplitting/
Thu, 21 Jul 2022 00:00:00 +0000
/python/numpyarrays/arraysplitting/
Table of Contents
Introduction
The numpy.split Function
Splitting of 1D Arrays
Splitting of 2D Arrays
Splitting of 3D Arrays
The numpy.array_split Function
The numpy.hsplit Function
The numpy.vsplit Function
Introduction
The opposite of concatenation is splitting, which means breaking up an array into multiple subarrays. It can be implemented by the functions numpy.split, numpy.hsplit and numpy.vsplit.
The numpy.split Function
The numpy.split function splits an array into multiple subarrays as views of the original array.

NumPy Array Concatenation
/python/numpyarrays/arrayconcatenation/
Tue, 19 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayconcatenation/
Table of Contents
Introduction
The numpy.concatenate Function
Joining 1D Arrays
Joining 2D Arrays
numpy.vstack: Joining Arrays Vertically
numpy.hstack: Joining Arrays Horizontally
numpy.stack: Joining Arrays Along a New Axis
Introduction
Concatenation means joining of two or more arrays into a single array. Several functions are available in NumPy to perform concatenation including numpy.concatenate, numpy.vstack, numpy.hstack and numpy.stack.
The numpy.concatenate Function
The numpy.concatenate function joins a sequence of arrays along an existing axis.

NumPy Array Iteration
/python/numpyarrays/arrayiteration/
Tue, 19 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayiteration/
Table of Contents
Introduction
Iterating Over a 1D Array
Iterating Over a 2D Array
Iterating Over a 3D Array
Introduction
Iterating over an array means going through the array element by element. We can easily perform this using the Python for loop. However, for large multidimensional arrays, there are certain tools available in NumPy to speed up the process.
Iterating Over a 1D Array
Once again, we begin by first importing the NumPy package and creating a random 1D array using the numpy.

Reshaping NumPy Arrays
/python/numpyarrays/arrayreshaping/
Mon, 18 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayreshaping/
Table of Contents
Introduction
Reshaping an Array
The NumPy base Attribute
reshape() Method Returns a View
The numpy.newaxis Method
The Unknown Dimension
Flattening an Array
Introduction
Reshaping an array means changing the shape of an array. To recap, the shape
attribute of an ndarray object returns a tuple that gives the lengths of the corresponding array dimensions. By reshaping an array, we can add or remove dimensions or change the length in each dimension.

NumPy Array Copy vs View
/python/numpyarrays/arraycopyview/
Mon, 18 Jul 2022 00:00:00 +0000
/python/numpyarrays/arraycopyview/
Table of Contents
Introduction
Python List Slices Return Copies
NumPy Array Slices Return Views
Creating Copies of NumPy Arrays
Introduction
NumPy array slices return views rather than copies of the original array. In other words, the copy is a new array whereas the view is just a view of the original array. This is in contrast to Python list slicing where list slices are copies.
The copy is independent of the original array and any changes made to the copy will not affect the original array.

NumPy Array Slicing
/python/numpyarrays/arrayslicing/
Sat, 16 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayslicing/
Table of Contents
Introduction
Slicing of 1D Arrays
Slicing with Positive Indices
Slicing with Mixed Indices
Slicing of 2D Arrays.
Slicing of 3D Arrays.
Introduction
Similar to Python lists, we can can also use access NumPy subarrays with the slice notation with the aid of the colon (:) character. The NumPy slicing syntax follows that of the standard Python list.
We begin this section by first importing the NumPy package and creating 3 random arrays using the numpy.

NumPy Array Indexing
/python/numpyarrays/arrayindexing/
Fri, 15 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayindexing/
Table of Contents
Introduction
The numpy.random.choice() Function
Array Indexing for 1D Arrays
Array Indexing for 2D Arrays
Array Indexing for 3D Arrays
Introduction
Array indexing is the same as accessing an array element. You can access an array element by referring to its index number, just like a Python list. The indices in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1, etc.

NumPy Array Attributes
/python/numpyarrays/arrayattributes/
Thu, 14 Jul 2022 00:00:00 +0000
/python/numpyarrays/arrayattributes/
Table of Contents
Introduction
The NumPy Array ndim Attribute
The NumPy Array shape Attribute
The NumPy Array size Attribute
The NumPy Array T Attribute
The NumPy Array dtype Attribute
The NumPy Array nbytes Attribute
The NumPy Array itemsize Attribute
Introduction
The NumPy ndarray object has a number of important attributes. In this section, we will discuss several important ones:
Attribute Description ndim Number of array dimensions. shape A tuple of integers representing the size of the array in each dimension.

Creating NumPy Arrays
/python/numpyarrays/createarrays/
Thu, 14 Jul 2022 00:00:00 +0000
/python/numpyarrays/createarrays/
Table of Contents
The NumPy ndarray Object
Setting the Data Type
Using Data Type Codes
Specifying the float64 Data Type
Specifying the int32 Data Type
Creating NumPy Arrays
Initializing NumPy Arrays
The numpy.eye() Function
The numpy.arange() Function
The numpy.linspace() Function
The NumPy ndarray Object
While the array object of Python’s array module provides efficient storage of arraybased data, NumPy’s ndarray object adds several more advantages:
efficient operations on the data via dozens of specialized functions.

NumPy Introduction
/python/numpyarrays/introduction/
Wed, 13 Jul 2022 00:00:00 +0000
/python/numpyarrays/introduction/
Table of Contents
What is NumPy?
Why Use NumPy?
Why is NumPy Faster Than Lists?
What is NumPy?
NumPy is a Python library used for working with arrays. NumPy stands for Numerical Python. It also has functions for working in domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005 by Travis Oliphant
. It is an open source project and you can use it freely. Why Use NumPy?