# Numpy - Part 1

## Machine Learning basics

Mahipal
·Apr 2, 2022·

💡Why Numpy ?

`````` 1️⃣ Numerical Operations are faster than normal python lists

2️⃣ Also known as Array Oriented Computing

3️⃣ Unlike lists, Numpy Array elements should be of same data type

4️⃣ package for creating Multi-Dimension Arrays
``````

some info on Arrays

18 is a Scalar (there is no dimension, so no Shape)

1️⃣ D Array = Vector (collection of scalars) [1, 2, 3, 4, 5]

It has 1 axes i.e., axis = 0

Shape is (N, ) - N is no. of scalars

here, Shape is (5, )

2️⃣ D Array = Matrix (collection of Vectors) [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]

It has 2 axes i.e., axis=0, axis=1

Shape is (N, M) - N is no. of vectors, M is no of scalars in each vector

here, Shape is (2, 5)

3️⃣ D Array (collection of Matrix's)

[[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], [[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]]

anything more than 2D array can be called Tensor

Shape is (N, M, P) - N number of Matrices each of shape (M, P)

here, Shape is (2, 3, 5)

💡 How to Create an Array ?

• 3 ways

import numpy as np

➖ np.array(your_list) your list or nested list to create 1D/higher dimension
arrays

➖ np.arange(5) - creates 1D Array read it as `a` range (range() in python)

➖ np.random.rand(5)

💡 Understand our Array

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

→ a.dtype # data type is dtype('int64') → a.dim # dimension is 1 → a.shape # shape is (4, ) → a.size # total number of elements

If you like the content, you could follow on twitter @nameismahipal