学习如逆水行舟,不进则退!
=========================================================
2018-2-3
1、安装Anaconda,使用3.X版本进行学习。
2018-2-8
学习numpy的接口用法;
import numpy
test_log = numpy.genfromtxt("testlog.txt", delimiter=",")
print(test_log)
is_value_empty = numpy.isnan(test_log[:,1])
test_log[is_value_empty,1] ='0'
test_2lie = test_log[:,1]
allnum = test_2lie.astype(float)
print(allnum.sum())
print(allnum.mean())
2018-2-12 练习矩阵bool型操作
2018-2-27 内积
a = np.array([[0, 3],
[1, 4]])
b = np.array([[2, 0],
[1, 6]])
#print(a*b)
# 0*2 + 3*1 =3, 0*0 + 3*6 = 18
# 1*2 + 4*1 =6, 1*0 + 4*6 = 24
print(a.dot(b))
print(np.dot(a,b))
2018-2-27 矩阵赋值
= 是浅拷贝,内存对象一致
view 内存对象不一致,但是数据值是相同的
copy 深拷贝,一个新的矩阵
import numpy as np
a = np.arange(15).reshape(3,5)
print (a)
b = a
print (b is a)
b[2,0] = 999
print (b)
print (a)
c = a.view()
print (c is a)
c[2,1] = 888
print (c)
print (a)
print (id(a))
print (id(c))
d = a.copy()
print (d is a)
d[2,2] = 777
print (d)
print (a)
2018-2-27 数据排序
import numpy as np
data = np.sin(np.arange(20)).reshape(5,4)
print(data.shape[1])
print(data.shape[0])
print (data)
ind = data.argmax(axis=0)
print (ind)
data_max = data[ind, range(data.shape[1])]
print (data_max)
b = np.sort(data, axis=1)
print (b)
print (data)
data.sort()
print (data)
c = np.array([4,2,5,7])
j = np.argsort(c)
print (j)
print (c[j])
k = np.tile(c, (3,4))
print (k)
print (k[0,5])
print (k.shape[1])
print (k.shape[0])
===
4
5
[[ 0. 0.84147098 0.90929743 0.14112001]
[-0.7568025 -0.95892427 -0.2794155 0.6569866 ]
[ 0.98935825 0.41211849 -0.54402111 -0.99999021]
[-0.53657292 0.42016704 0.99060736 0.65028784]
[-0.28790332 -0.96139749 -0.75098725 0.14987721]]
[2 0 3 1]
[ 0.98935825 0.84147098 0.99060736 0.6569866 ]
[[ 0. 0.14112001 0.84147098 0.90929743]
[-0.95892427 -0.7568025 -0.2794155 0.6569866 ]
[-0.99999021 -0.54402111 0.41211849 0.98935825]
[-0.53657292 0.42016704 0.65028784 0.99060736]
[-0.96139749 -0.75098725 -0.28790332 0.14987721]]
[[ 0. 0.84147098 0.90929743 0.14112001]
[-0.7568025 -0.95892427 -0.2794155 0.6569866 ]
[ 0.98935825 0.41211849 -0.54402111 -0.99999021]
[-0.53657292 0.42016704 0.99060736 0.65028784]
[-0.28790332 -0.96139749 -0.75098725 0.14987721]]
[[ 0. 0.14112001 0.84147098 0.90929743]
[-0.95892427 -0.7568025 -0.2794155 0.6569866 ]
[-0.99999021 -0.54402111 0.41211849 0.98935825]
[-0.53657292 0.42016704 0.65028784 0.99060736]
[-0.96139749 -0.75098725 -0.28790332 0.14987721]]
[1 0 2 3]
[2 4 5 7]
[[4 2 5 7 4 2 5 7 4 2 5 7 4 2 5 7]
[4 2 5 7 4 2 5 7 4 2 5 7 4 2 5 7]
[4 2 5 7 4 2 5 7 4 2 5 7 4 2 5 7]]
2
16
3
2018-2-28 矩阵归一化
import numpy as np
z = np.random.random((3,3))
print (z)
a , b = z.min(), z.max()
print (a)
print (b)
a = np.array([1,2,3])
x = z + a
print (x)
#归一化
y = (x - x.min())/(x.max() - x.min())
print (y)
[[ 0.95219215 0.93771665 0.64158953]
[ 0.48924913 0.14551862 0.33236475]
[ 0.79020678 0.51215386 0.67116962]]
0.145518615237
0.952192153817
[[ 1.95219215 2.93771665 3.64158953]
[ 1.48924913 2.14551862 3.33236475]
[ 1.79020678 2.51215386 3.67116962]]
[[ 0.21217227 0.66384982 0.9864431 ]
[ 0. 0.30077608 0.84472172]
[ 0.13793245 0.46880935 1. ]]