File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments