Breaking News

# Data Science

## Combine & Split an Array

10 – Combine & Split an Array In : import numpy as np In : arr1 = np.array([[1,2,3,4], [1,2,3,4]]) arr2 = np.array([[5,6,7,8], [5,6,7,8]]) np.concatenate((a, b), axis=0)¶ In : arr1 Out: array([[1, 2, 3, 4], [1, 2, 3, 4]]) In : arr2 Out: array([[5, 6, 7, 8], [5, 6, 7, 8]]) In : # concat along …

## Array Manipulation

9 – Manipulate an Array Numpy Array Manipulation¶ In : import numpy as np In : arr = np.random.randint(1,10,[3,3]) arr Out: array([[7, 4, 7], [5, 3, 6], [2, 1, 4]]) Transpose an array¶ In : print(arr.T) [[7 5 2] [4 3 1] [7 6 4]] or¶ In : print(np.transpose(arr)) [[7 5 2] [4 3 …

## NumPy Array Sorting

8 – Sort an Array Sorting of an Array¶ In : import numpy as np In : import numpy as np arr = np.array([[30,17,15],[19,90,16],[69,53,21]]) arr Out: array([[30, 17, 15], [19, 90, 16], [69, 53, 21]]) sort an array along a specified axis¶ In : # sort along the row and return a copy …

## Numpy Slicing & Indexing

7 – Slicing & Indexing Subset, Slice, Index and Iterate through Arrays¶For one-dimensional arrays, indexing, slicing etc. is similar to python lists – indexing starts at 0. Slicing arrays¶Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: …

## Numpy Mathematic Functions

6 – Math Functions NumPy Math Functions¶ In : import numpy as np In : arr = np.random.randint(10,99,[3,3]) arr Out: array([[45, 53, 78], [81, 88, 25], [71, 55, 59]]) Element-wise addition, subtraction, multiplication and division¶ In : print(arr + 10) print(arr - 10) print(arr * 10) print(arr / 10) [[55 63 88] [91 …

## Numpy Random Array

5 – Random Array NumPy Random Array¶ In : import numpy as np In : # generate a random scalar print(np.random.rand()) 0.2224104911171324 In : # generate a 1-D array print(np.random.rand(3)) [0.69589689 0.9990713 0.77034202] In : # generate a 2-D array print(np.random.rand(3,3)) [[0.2151302 0.64925559 0.95982155] [0.02673682 0.33937101 0.78181161] [0.39285799 0.7581885 0.15635241]] Generate a sample from …

## Inspect an Array

4 – Inspect an Array Inspect NumPy Array¶ In : import numpy as np In : arr = np.array([[1,2,3], [4,5,6]], dtype=np.int64) arr Out: array([[1, 2, 3], [4, 5, 6]], dtype=int64) Inspect general information of an array¶ In : print(np.info(arr)) class: ndarray shape: (2, 3) strides: (24, 8) itemsize: 8 aligned: True contiguous: True …

## Numpy Datatypes

3 – Numpy Data Types NumPy Data Types¶ In : import numpy as np import pandas as pd Data Types in NumPy¶Numpy has the following data types: int float complex bool string unicode object The numeric data types have various precisions like 32-bit or 64-bit. Numpy data types can be represented …