-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvideo26.py
160 lines (104 loc) · 2 KB
/
video26.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- coding: utf-8 -*-
"""Video26.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/16_B_DSL2zF3YodDWMlNwgsO8kJ2_JbFE
"""
import numpy as np
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])
a
a.dtype
a[1,2]
a[1,2] = -7
a
# range (i, m ) i.........m-1
for i in range(5,10):
print(i, end=" ")
# x:m => x.x+1.x+2.......m-1
#a[0:2, 1:3]
a[:2, 1:3]
a[:,:]
a[:,1:4]
data = [[3.1,2.2,5.1,1],
[4.2,5.1,3.4,0],
[3.1,0.2,5.1,1],
[8.2,7.2,-11,1]]
data = np.array(data)
x = data[:,:3]
y = data[:,-1]
x
y
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])
from math import sqrt
bool_a = (a==int(sqrt(36)))
bool_a
a[a > 5]
r = np.random.random(20)
r
r.reshape((5,4))
rr = r[r > 0.6]
rr
rr.shape
rr.reshape(2,5)
x = np.array([1,2,-3,5,8,9,4,-200,124,0])
x
x.sort()
x
x = np.array([2,-3,4,-200,124,0])
for i in range(x.size-1):
if x[i]>x[i+1]:
x[i],x[i+1]=x[i+1],x[i]
x
for i in range(x.size-1):
if x[i]>x[i+1]:
x[i],x[i+1]=x[i+1],x[i]
x
for i in range(x.size-1):
if x[i]>x[i+1]:
x[i],x[i+1]=x[i+1],x[i]
x
x.size
len([1,2,3,4,5,6])
x = np.array([1,2,-3,5,8,9,4,-200,124,0])
for j in range(x.size-1):
for i in range(x.size-1):
if x[i]>x[i+1]:
#x[i],x[i+1]=x[i+1],x[i]
t = x[i]
x[i] = x[i+1]
x[i+1]= t
x
def array_sort(array):
for j in range(array.size-1):
for i in range(array.size-1):
if array[i]>array[i+1]:
#array[i],array[i+1]=array[i+1],array[i]
t = array[i]
array[i] = array[i+1]
array[i+1]= t
return array
x = np.array([11,22,-30,5,80,90,4,-2000,124,0])
z = array_sort(x)
z
z.dtype
y = np.array([11,22,-30,5,80,90,4,-2000,124,0])
m,n = 1 ,2
y
from math import pow
def fff(a,b):
a = pow(a,b)
b = a+b
return b
print(fff(m,n))
print(m,n)
y_sorted = array_sort(y)
y
y_sorted
from sklearn import datasets
iris = datasets.load_iris()
iris.data
iris.target