-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumPy.py
More file actions
64 lines (39 loc) · 1.87 KB
/
Copy pathNumPy.py
File metadata and controls
64 lines (39 loc) · 1.87 KB
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
63
64
#-------NumPy----------
#it is Num-numerical Py-python
#----Array Function in NumPy---------
#it is create a fixed number of evenly spaced values
import numpy as np # import the library
M = np.array([3,2,5]) # calling lib logic
print(M) #Output: [3 2 5]
print(M.ndim) #find out which dimention ---> Output: 1
arr=np.array(32) #only single value give output in (), extra values in ([ ])
print(arr) #Output: 32
#-----linspace Function in Numpy--------------
#it is Even spaced number
#here np.linspace(start, stop, num)
import numpy as np
M = np.linspace(1,10,4) #start=1,stop=10,num=4
#here between 1 to 10 -> 9 values their , num = 4values - 3gaps(4-1)
print(M) #OutPut : [ 1. 4. 7. 10.]
#-----Logspace Function in NumPy---------------
#it is even spaced power of 10
#np.logspace(start,stop,num,base=value) here base is (10)fixed if we not given also
import numpy as np
M=np.logspace(3,2,2) #base fixed (10)
print(M) #Output : [1000. 100.]
#-------arange Function NumPy-------------
#it is create values using a fixed step size
#np.range(start,stop,step) --> start=first value, stop ending limit(not included), step=increment value
import numpy as np
M=np.arange(0,10,2) #0, 0+2=2, 2+2=4, 4+2=6, 6+2=8 8+2=10
print(M) #Output: [0 2 4 6 8]
#we can do slicing for this
print(M[2:4]) #Output : [4 6]
#-------zeros and ones Function----------
import numpy as np
M=np.zeros(2)
print(M) #Output: [0. 0.]
N=np.ones((3,2))
print(N) #Output: [[1. 1.]
# [1. 1.]
# [1. 1.]]