-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumerical-calculations.py
More file actions
66 lines (52 loc) · 1019 Bytes
/
numerical-calculations.py
File metadata and controls
66 lines (52 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 13:58:07 2018
@author: asanka
"""
import numpy as np
# Numpy array initializations
x = np.array([10, 20, 30, 40])
print(x)
x = np.arange(1, 2, 0.25)
print(x)
x = np.zeros(5)
print(x)
# Numpy Array elements can be updated
x[0] = 10
x[2] = 30
print(x)
# Select a range of numpy array elements
print("")
print("Selecting Ranges x[start_index:end_index]")
print(x[0:3])
print(x[1:3])
# Defining metrices as numpy arrays
print("")
print("Matrices")
x = np.array([ [1,2,3], [4,5,6] ])
print(x)
x = np.zeros((5,6))
print(x)
# Accessing matrix elements
print("")
print("Assigning values to matrix elements")
x[0,0] = 10
x[0,1] = 20
x[0,2] = 30
x[1,0] = 40
x[1,1] = 50
x[1,2] = 60
print(x)
print("")
print("All the rows but first column")
print(x[:,0])
print("")
print("All the columns but first row")
print(x[0,:])
# Numpy arrays can be converted back to lists or tuples
print("")
x = np.array([1, 2, 3])
print(x)
print(list(x))
print(tuple(x))