Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b89b507

Browse files
author
Juzer Shakir
committed
Optimized code for better readability.
1 parent 22f07da commit b89b507

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

How_to_Python/Modules/Numpy/Numpy_operation_2.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,84 @@
1717
a = np.array([(1, 2, 3), (4, 5, 6)])
1818

1919
#----9
20-
#Finding sum of the elemnts by columns
21-
#axis = 0 means column
22-
colsum = a.sum(axis = 0)
20+
# Finding sum of the elemnts by columns
21+
# axis = 0 means column
22+
colsum = a.sum(axis=0)
2323
print("\nThe sum of all the value in the array by columns are {}".format(colsum))
24-
#Finding sum of the elemnts by rows
25-
#axis = 1 means rows
26-
rowsum = a.sum(axis = 1)
24+
# Finding sum of the elemnts by rows
25+
# axis = 1 means rows
26+
rowsum = a.sum(axis=1)
2727
print("\nThe sum of all the value in the array by rows are {}".format(rowsum))
2828
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
2929

3030
#----10
31-
#Finding sqaure root of each element in the array
31+
# Finding sqaure root of each element in the array
3232
sqrt = np.sqrt(a)
3333
print("\nThe sqaure root of each elements are \n{}".format(sqrt))
3434
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
3535

3636
#----11
37-
#Finding standard deviation of the array
37+
# Finding standard deviation of the array
3838
stnd = np.std(a)
3939
print("\nThe standard deviation of array is \n{}".format(stnd))
4040
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
4141

42-
#lets set another numpy array for performing arithmetic calculations
42+
# lets set another numpy array for performing arithmetic calculations
4343
b = np.array([(10, 11, 12), (13, 14, 15)])
4444
print("\nAnother numpy array given for calculations \n{}".format(b))
4545
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
4646

4747
#-----12
48-
#Finding the sum of two arrays
48+
# Finding the sum of two arrays
4949
asumb = a + b
5050
print("\nThe sum of two arrays are \n{}".format(asumb))
51-
#Finding the substraction of two arrays
51+
# Finding the substraction of two arrays
5252
aminusb = a - b
5353
print("\nThe substraction of two arrays are \n{}".format(aminusb))
54-
#Finding the multiplication of two arrays
54+
# Finding the multiplication of two arrays
5555
amultib = a * b
5656
print("\nThe multiplication of two arrays are \n{}".format(amultib))
57-
#Finding the division of two arrays
57+
# Finding the division of two arrays
5858
adivb = a / b
5959
print("\nThe division of two arrays are \n{}".format(adivb))
6060
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
6161

6262
#---13
63-
#Concatinating numpy's vertically
63+
# Concatinating numpy's vertically
6464
vstack = np.vstack((a, b))
6565
print("\nVertically stacked numpy's \n{}".format(vstack))
66-
#Concatinating numpy's horizontally
66+
# Concatinating numpy's horizontally
6767
hstack = np.hstack((a, b))
6868
print("\nHorizontally stacked numpy's \n{}".format(hstack))
6969
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
7070

7171
#----14
72-
#Combining columns of a numpy into a single column
72+
# Combining columns of a numpy into a single column
7373
single_a = a.ravel()
7474
print("\nThe first numpy array now have a single column\n{}".format(single_a))
7575
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
7676

7777
#----15
78-
#Exponential function
78+
# Exponential function
7979
ex_a = np.exp(a)
8080
print("\nThe elements of the first numpy array raised to the e power =\n{}".format(ex_a))
81-
#logarithmic function
82-
#natural logarithmic (ln)
81+
# logarithmic function
82+
# natural logarithmic (ln)
8383
log_a = np.log(a)
8484
print("\nThe natural log of the elements of the first numpy array =\n{}".format(log_a))
85-
#logarithmic (ln) with base 10 or log
85+
# logarithmic (ln) with base 10 or log
8686
log_a = np.log10(a)
8787
print("\nThe log with base 10 of the elements of the first numpy array =\n{}".format(log_a))
8888
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
8989

9090
#---16
91-
#the first value passed in the argument will be the value to start with
92-
#second will be the value to end at
93-
#third will be how many numbers do you want in between first and second arguments
91+
# the first value passed in the argument will be the value to start with
92+
# second will be the value to end at
93+
# third will be how many numbers do you want in between first and second arguments
9494
al = np.linspace(1, 5, 10)
9595
print("\nThese are 10 numbers in between 1 and 5 \n{}".format(al))
9696
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
9797

9898

99-
#That's it!
99+
# That's it!
100100
print("\nThe End!")

0 commit comments

Comments
 (0)