Numpy for data science!

Numpy for data science!

Numpy for data science!

Hello, how are you today? hope you are fine?????

Today let's dive in into data science with what we call "Numpy"

What is numpy?

NumPy is a python library used for working with arrays.

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.

NumPy stands for Numerical Python.

So enough of the intro let dive in>>>>

Installation

pip install numpy

Lets write our first numpy code

import numy as np
arr = np.array([1,2,3,4,5])
print (arr)

Result

[1 2 3 4 5]

What this does is it creates a array easily using numpy

you can check the type of the np array you created by typing

print(type(arr))

Result

<class 'numpy.ndarray'>

Dimensions in Arrays

A dimension in arrays is one level of array depth (nested arrays).

0-D Arrays

0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array.

Example Create a 0-D array with value 42

import numpy as np

arr = np.array(42)

print(arr)

1-D Arrays

An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array.

These are the most common and basic arrays.

Example Create a 1-D array containing the values 1,2,3,4,5:

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr)

2-D Arrays

An array that has 1-D arrays as its elements is called a 2-D array.

These are often used to represent matrix or 2nd order tensors.

NumPy has a whole sub module dedicated towards matrix operations called numpy.mat

Example Create a 2-D array containing two arrays with the values 1,2,3 and 4,5,6:

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

print(arr)

3-D arrays

An array that has 2-D arrays (matrices) as its elements is called 3-D array.

These are often used to represent a 3rd order tensor.

Example Create a 3-D array with two 2-D arrays, both containing two arrays with the values 1,2,3 and 4,5,6:

import numpy as np

arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])

print(arr)

so let stop there numpy is alot to handle this is just a quick phrase to learn more visit https://www.w3schools.com/python/numpy_creating_arrays.asp

Shalom!