Skip to content

Commit 92e6056

Browse files
committed
Intro and Basics of Numpy
1 parent cec623d commit 92e6056

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Numpy/P01_Introduction.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Author: OMKAR PATHAK
2+
3+
# NumPy (Numeric Python) is a Python package used for building multi dimensional arrays and performing
4+
# various operations
5+
6+
# In this program we will walk through various concepts and see available functions in the NumPy package.
7+
8+
# For installing: pip3 install numpy
9+
10+
import numpy as np
11+
12+
# we have a function arange() which makes an array of the specified dimension. Example:
13+
myArray = np.arange(20)
14+
print(myArray) # [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]
15+
16+
# an array from 10 to 20
17+
myArray = np.arange(10, 20) # [10 11 12 13 14 15 16 17 18 19]
18+
print(myArray)
19+
20+
# an array from 10 to 20 with 2 steps
21+
myArray = np.arange(10, 20, 2)
22+
print(myArray) # [10 12 14 16 18]
23+
24+
# reshape() helps to reshape our NumPy array
25+
myArray = np.arange(20)
26+
# syntax: reshape(number_of_rows, number_of_columns)
27+
myArray = myArray.reshape(4, 5)
28+
print(myArray)
29+
30+
# [[ 0  1  2  3  4]
31+
#  [ 5  6  7  8  9]
32+
#  [10 11 12 13 14]
33+
#  [15 16 17 18 19]]
34+
35+
myArray = myArray.reshape(10, 2)
36+
print(myArray)
37+
38+
# [[ 0  1]
39+
#  [ 2  3]
40+
#  [ 4  5]
41+
#  [ 6  7]
42+
#  [ 8  9]
43+
#  [10 11]
44+
#  [12 13]
45+
#  [14 15]
46+
#  [16 17]
47+
#  [18 19]]
48+
49+
# shape returns the shape of the array. The length of shape tuple is called as rank (or dimension)
50+
print(myArray.shape) # (10, 2)
51+
52+
# ndim returns the dimension (rank) of the array
53+
print(myArray.ndim) # 2
54+
55+
# size returns the total number of elements in the array
56+
print(myArray.size) # 20
57+
58+
# to check the data we have dtype.
59+
print(myArray.dtype) # int64

0 commit comments

Comments
 (0)