Category: NumPy
-
NumPy Filter Array
Filtering Arrays Getting some elements out of an existing array and creating a new array out of them is called filtering. In NumPy, you filter an array using a boolean index list. A boolean index list is a list of booleans corresponding to indexes in the array. If the value at an index is True that element is contained in the…
-
NumPy Splitting Array
Splitting NumPy Arrays Splitting is reverse operation of Joining. Joining merges multiple arrays into one and Splitting breaks one array into multiple. We use array_split() for splitting arrays, we pass it the array we want to split and the number of splits. ExampleGet your own Python Server Split the array in 3 parts: import numpy as np arr = np.array([1, 2, 3, 4, 5, 6])…
-
NumPy Joining Array
Joining NumPy Arrays Joining means putting contents of two or more arrays in a single array. In SQL we join tables based on a key, whereas in NumPy we join arrays by axes. We pass a sequence of arrays that we want to join to the concatenate() function, along with the axis. If axis is not explicitly…
-
NumPy Array Iterating
Iterating Arrays Iterating means going through elements one by one. As we deal with multi-dimensional arrays in numpy, we can do this using basic for loop of python. If we iterate on a 1-D array it will go through each element one by one. ExampleGet your own Python Server Iterate on the elements of the following 1-D…
-
NumPy Array Reshaping
Reshaping arrays Reshaping means changing the shape of an array. The shape of an array is the number of elements in each dimension. By reshaping we can add or remove dimensions or change number of elements in each dimension. Reshape From 1-D to 2-D ExampleGet your own Python Server Convert the following 1-D array with…
-
NumPy Array Shape
Shape of an Array The shape of an array is the number of elements in each dimension. Get the Shape of an Array NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements. ExampleGet your own Python Server Print the shape of a 2-D array: The example…
-
NumPy Array Copy vs View
The Difference Between Copy and View The main difference between a copy and a view of an array is that the copy is a new array, and the view is just a view of the original array. The copy owns the data and any changes made to the copy will not affect original array, and any changes…
-
NumPy Data Types
Data Types in Python By default Python have these data types: Data Types in NumPy NumPy has some extra data types, and refer to data types with one character, like i for integers, u for unsigned integers etc. Below is a list of all data types in NumPy and the characters used to represent them. Checking the Data Type…
-
NumPy Array Slicing
Slicing arrays Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end]. We can also define the step, like this: [start:end:step]. If we don’t pass start its considered 0 If we don’t pass end its considered length of array in that dimension If we…
-
NumPy Array Indexing
Access Array Elements Array indexing is the same as accessing an array element. You can access an array element by referring to its index number. The indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1 etc. ExampleGet your own Python Server Get the…