机器学习
愣头青的学
这个人以为自己很帅
展开
-
numpy中几个方便观察矩阵的属性
import numpya = numpy.arange(20).reshape(2,2,5)aarray([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]])a.shape>>>(2, 2, ...原创 2018-03-30 09:34:12 · 810 阅读 · 0 评论 -
numpy中矩阵乘法,星乘(*)和点乘(.dot)的区别
import numpya = numpy.array([[1,2], [3,4]])b = numpy.array([[5,6], [7,8]])a*b>>>array([[ 5, 12], [21, 32]])a.dot(b)>>>array([[19, 22],...原创 2018-03-30 11:08:02 · 222388 阅读 · 11 评论 -
numpy中矩阵的常用操作
import numpy#取(-1,1)随机数,shape为(3,4),向下取整a = numpy.floor(10 * numpy.random.random((3,4)))print(a)print("--------->")print(a.ravel())print("--------->")a.shape = (6,2)print(a)print("-----...原创 2018-03-30 11:49:59 · 959 阅读 · 0 评论 -
numpy.array的运算----true和false
import numpya = numpy.array([[10,20,30],[40,50,60]])#b表示a这个2维数组里面1维数组的第1个元素,即10==40 False、40==40 Trueb = a[:,0] == 40#此时b为[False True],给b赋值5,false赋值失败,true赋值成功a[b,0] = 5print(a.shape)print(a...原创 2018-03-29 16:29:27 · 7246 阅读 · 0 评论 -
numpy中sum(axis=1)与sum(axis=0)的区别
import numpya = numpy.array([ [[5,10,15], [10,20,30], [20,40,60]], [[5,10,15], [10,20,30], [20,40,60]]])#按行相加,此时第一、二行都是[5,10,15],[10,20,30],[20,40,60]b = a.sum(axis=1)...原创 2018-03-29 17:10:10 · 7566 阅读 · 1 评论