-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy.txt
More file actions
72 lines (63 loc) · 2.86 KB
/
numpy.txt
File metadata and controls
72 lines (63 loc) · 2.86 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
65
66
67
68
69
70
71
72
numpy
for multidimenstional array we cant use module we have to import module name numpy which do not come by default with python so
installation in cmd
pip install numpy where pip command is used to install python package
using numpy we can create an array using 6 different functions such as
array()
linspace()
logspace()
arange()
zeroes()
ones()
1.array()=array function in numpy we just need to pass an collection of element to pass data type of an array is an optional it will automatically guess the datatype based on the type of value
import numpy
val=numpy.array([20, 10, 20.9,],int) #data type argument is optional
print(val.dtype,val)
output
int32 [20 10 20]
import numpy
val=numpy.array([20, 10, 20.9,])
print(val.dtype,val)
output
float64 [20. 10. 20.9]
2.linspace()=it is an another function which is used to create array we need to pass three argunment which is (start=where the array should start,stop=where the a should stop ,part=number of part it should devide)
by default part is part is 50
and it return float array because it has to devide array in part
diffrence between two parts as same in linspace
line=numpy.linspace(0,15,10)
print(line,line.dtype)
output
[ 0. 1.66666667 3.33333333 5. 6.66666667 8.33333333
10. 11.66666667 13.33333333 15. ]
float64
dtype return the type of array
3.ara=numpy.arange(20)
print(ara,ara.dtype)
output
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19] int32
ara=numpy.arange(20,22,0.5)
print(ara,ara.dtype)
output
[20. 20.5 21. 21.5] float64
in this function we need to pass three value where (start,stop,step) start=where to start stop=stop-step,step=indentation between element if we pass only one value then it is stop and start is by default 0 and step is 1
4.logspace is same as linspace but the diffrrence is that in linspace diffrence is same between element and in logspace the diffrence is depend on the log
log=numpy.logspace(1,10,20)
print(log)
output
[1.00000000e+01 2.97635144e+01 8.85866790e+01 2.63665090e+02
7.84759970e+02 2.33572147e+03 6.95192796e+03 2.06913808e+04
6.15848211e+04 1.83298071e+05 5.45559478e+05 1.62377674e+06
4.83293024e+06 1.43844989e+07 4.28133240e+07 1.27427499e+08
3.79269019e+08 1.12883789e+09 3.35981829e+09 1.00000000e+10]
argument pass is start stop and part in logspace
5.zero=numpy.zeros(10)
print(zero)
output
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
when we want to create an array with all the element zero we use the function zeros it will initilise the element to 0 and we have to pass the size of the array in function
6.ones()
ones=numpy.ones(5)
print(ones)
output
[1. 1. 1. 1. 1.]
when we want to create an array with all the element one we use the function ones it will initilise the element to 1 and we have to pass the size of the array in function