Skip to content

Commit 934d355

Browse files
authored
Add files via upload
1 parent b58f2ec commit 934d355

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

NumPy.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import numpy as np
2+
import time
3+
import sys
4+
5+
6+
a = np.array([1,2,3])
7+
print(a)
8+
9+
b = np.array([[1,2,3], [4,5,6]])
10+
print(b)
11+
12+
S = range(1000)
13+
print(S)
14+
print(sys.getsizeof(5)*len(S)) # List - size of one element multiplied by the number of all elements, so we got the size of all elements
15+
print(sys.getsizeof(5)) #size of one element
16+
17+
D = np.arange(1000)
18+
print(D.size * D.itemsize) # NumPy - size of one element multiplied by the number of all elements, so we got the size of all elements
19+
20+
SIZE = 1000000
21+
L1 = range(SIZE)
22+
L2 = range(SIZE)
23+
24+
A1 = np.arange(SIZE)
25+
A2 = np.arange(SIZE)
26+
27+
start = time.time()
28+
result = [(x,y) for x,y in zip(L1, L2)]
29+
30+
print ((time.time() - start) * 1000 ) #runtime of List
31+
32+
start = time.time()
33+
result = A1 + A2
34+
35+
print ((time.time() - start) * 1000 ) #runtime of Numpy
36+
37+
38+
a = np.array([(1,2,3),(2,3,4)])
39+
print(a.ndim) #dimention of array
40+
print(a.itemsize) #byte size of each element
41+
print(a.dtype) #data type
42+
print(a.size) #size of array
43+
print(a.shape) #shape of array
44+
a = a.reshape(3, 2) #reshape into 3 rows and 2 collums
45+
print(a)
46+
47+
a = np.array([(1,2,3),(2,3,4),(5,6,8)])
48+
print(a[0:2,1]) #slicing
49+
50+
a = np.linspace(1,3,10) #slicing
51+
print(a)
52+
53+
a = np.array([(1,2,3),(2,3,4),(5,6,8)])
54+
print(a.max())
55+
print(a.min())
56+
print(a.sum())

0 commit comments

Comments
 (0)