Skip to content

Commit f767cc4

Browse files
committed
Add scientific package: Numpy
1 parent 1bf2c44 commit f767cc4

File tree

5 files changed

+101
-5
lines changed

5 files changed

+101
-5
lines changed

.idea/FromCodingToDeepLearning.iml

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/other.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Author: Nguyen Truong Thinh
2+
# Contact me: [email protected] || +84393280504
3+
#
4+
# Package & libraries for scientific computing section
5+
from matplotlib import pyplot as plt
6+
7+
import numpy as np
8+
9+
# Mathematical functions
10+
print(np.log(32))
11+
print(np.exp(3))
12+
print(np.sin(2))
13+
print(np.cos(2))
14+
15+
# Numpy arrays: Single dimensional
16+
my_arr = np.array([0, 1, 3, 4, 5])
17+
print(my_arr)
18+
19+
my_arr = np.array(range(0, 10))
20+
print(my_arr)
21+
22+
my_arr = np.linspace(1.1, 4.8, num=6)
23+
print(my_arr)
24+
print("\nmy array type is: ", type(my_arr))
25+
print("\nThe first element is: ", my_arr[0])
26+
27+
my_arr[0] = 1.0
28+
print("\nThe first element is now: ", my_arr[0])
29+
30+
my_arr[0:4] = 99
31+
print('\nThe my array is now:', my_arr)
32+
print('\nThe max of my array is: ', my_arr.max())
33+
print('\nThe min of my array is: ', my_arr.min())
34+
print('The mean of my array is: ', my_arr.mean())
35+
# Numpy arrays: Multi-dimensional
36+
_2d_matrix = np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
37+
print(_2d_matrix)
38+
print('\nThe matrix dimensions are: ', _2d_matrix.shape)
39+
print('\nElement in first row, third column is: ', _2d_matrix[0, 2])
40+
print('\nElement in second row, fifth column is: ', _2d_matrix[1, 4])
41+
42+
rs_2d_matrix = _2d_matrix.reshape(5, 2)
43+
print('\nReshaped matrix is: \n', rs_2d_matrix)
44+
trans_2d_matrix = _2d_matrix.transpose()
45+
print('\nTransposed matrix is: \n', trans_2d_matrix)
46+
into_lines = _2d_matrix.ravel()
47+
print('\nUnraveled matrix is: \n', into_lines)
48+
49+
array_zeros = np.zeros((3, 5))
50+
print('\n', array_zeros)
51+
array_ones = np.ones((8, 9))
52+
print('\n', array_ones)
53+
array_pi = np.full((3, 7), 3.14159)
54+
print('\n', array_pi)
55+
56+
_3d_matrix = np.ones((3, 5, 3))
57+
print('\n 3D matrix: \n', _3d_matrix)
58+
59+
array_ones[2:6, 2:] = 8.95
60+
print('My large matrix of ones is now: \n', array_ones)
61+
62+
arr_1 = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
63+
arr_2 = np.array([[3, 6, 9], [12, 9, 15], [6, 36, 63]])
64+
print('Array 1:\n', arr_1)
65+
print('Array 2: \n', arr_2)
66+
array_3 = arr_2 + np.sin(arr_1) - arr_1 / arr_2
67+
print('\nArray 3:\n', array_3)
68+
69+
other_array = np.array([1, 2, 3, 4, 5])
70+
for i in other_array:
71+
print(i**3 + i)
72+
73+
x = np.array(range(0, 9))
74+
y = np.sqrt(x)
75+
plt.plot(x, y)
76+
print('\nMy an other array y has values: ', y)
77+

main.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@
5656
print('Is There A specialized Key?: ', 'specialized' in info_dict_dev)
5757
# Logic & Loops
5858
for i in range(0, 10):
59-
boolIsGreaterThanSix = (i >= 3)
59+
boolIsGreaterThanThree = (i >= 3)
6060
if i == 5:
6161
print('Ignores at 5, continues at i = 6')
6262
continue
6363
if i == 9:
6464
print('Over flow at i = 9')
6565
break
66-
print(f'{i} - Spam: {boolIsGreaterThanSix}')
66+
print(f'{i} - Spam: {boolIsGreaterThanThree}')
6767

6868
for i in range(0, 30):
6969
my_step_by_steps = (i % 3)
@@ -72,6 +72,13 @@
7272

7373
cube_nums = [i ** 3 for i in range(10)]
7474
print(cube_nums)
75+
76+
a_number = 20
77+
while a_number > 10:
78+
a_number -= 3
79+
if a_number < 10:
80+
break
81+
print("value: ", a_number)
7582
# Custom functions
7683
friends_stock_list = [info_dict_dev, info_dict_tester, info_dict_po, info_dict_boss]
7784
data = get_data_from_list(friends_stock_list)

0 commit comments

Comments
 (0)