示例#1
0
 def test_empty(self):
     a = np.array([[[]]])
     b = np.array([[], []])
     c = tile(b, 2).shape
     d = tile(a, (3, 2, 5)).shape
     assert_equal(c, (2, 0))
     assert_equal(d, (3, 2, 0))
示例#2
0
    def __init__(self, L, N):
        self.deltaX = float(L / float(N))
        self.N = int(N + 1)
        self.M = self.N
        self.L = float(L)
        self.X = []
        # TODO !!! move this part to __call__ method

        self.A = array(zeros([self.M, self.M]))

        #self.filtera = array(self.A +1, dtype=bool)
        self.filtera = self.A == self.A  # COOL ! :)
        self.DOF = array(tile(True, (self.M)), dtype=bool)
        for i in range(self.M):  # assuming DX=Constant
            self.X.append(round(self.deltaX * i, 15))  # To avoid  stupid 0.199

        self.B = array(zeros([self.M, 1]))
        self.T = array(tile(nan, (self.M, )))

        # TODO for solve method
        self.bcConduction = array(tile(False, (self.M, )), dtype=bool)
        self.bcConvection = array(tile(False, (self.M, )), dtype=bool)
        self.bcT = array(tile(True, (self.M, )), dtype=bool)
        #self.bcRadiation = array(tile(False, (self.M, 1)), dtype=bool)

        internalNodes = array([1., -2., 1.])
        #
        for i in range(1, int(self.M - 1)):
            #            self.A[i, range(i-1, i+2)] = internalNodes
            self.B[i] *= self.deltaX**2
示例#3
0
 def test_empty(self):
     a = np.array([[[]]])
     b = np.array([[], []])
     c = tile(b, 2).shape
     d = tile(a, (3, 2, 5)).shape
     assert_equal(c, (2, 0))
     assert_equal(d, (3, 2, 0))
示例#4
0
    def __init__(self, L, N):
        self.deltaX = float(L / float(N))
        self.N = int(N + 1)
        self.M = self.N
        self.L = float(L)
        self.X = []
        # TODO !!! move this part to __call__ method

        self.A = array(zeros([self.M, self.M]))



        #self.filtera = array(self.A +1, dtype=bool)
        self.filtera = self.A == self.A         # COOL ! :)
        self.DOF = array(tile(True, (self.M)), dtype=bool)
        for i in range(self.M):         # assuming DX=Constant
            self.X.append(round(self.deltaX*i, 15))   # To avoid  stupid 0.199

        self.B = array(zeros([self.M, 1]))
        self.T = array(tile(nan, (self.M,)))

        # TODO for solve method
        self.bcConduction = array(tile(False, (self.M, )), dtype=bool)
        self.bcConvection = array(tile(False, (self.M, )), dtype=bool)
        self.bcT = array(tile(True, (self.M, )), dtype=bool)
        #self.bcRadiation = array(tile(False, (self.M, 1)), dtype=bool)

        internalNodes = array([1., -2., 1.])
#
        for i in range(1, int(self.M-1)):
#            self.A[i, range(i-1, i+2)] = internalNodes
            self.B[i] *= self.deltaX**2
def auto_toOne(matrix):
    result=zeros((matrix.shape[0],matrix.shape[1]))
    rows=matrix.shape[0];
    coloum=matrix.shape[1];
    ran=zeros((1,coloum));
    ran=matrix.max(0)-matrix.min(0)
    
    norMatrix=matrix-tile(matrix.min(0),(rows,1))
    result=norMatrix/tile(ran,(rows,1))
    return result,ran,matrix.min(0)
示例#6
0
    def test_kroncompare(self):
        from numpy.random import randint

        reps = [(2,), (1, 2), (2, 1), (2, 2), (2, 3, 2), (3, 2)]
        shape = [(3,), (2, 3), (3, 4, 3), (3, 2, 3), (4, 3, 2, 4), (2, 2)]
        for s in shape:
            b = randint(0, 10, size=s)
            for r in reps:
                a = np.ones(r, b.dtype)
                large = tile(b, r)
                klarge = kron(a, b)
                assert_equal(large, klarge)
示例#7
0
    def test_kroncompare(self):
        from numpy.random import randint

        reps = [(2,), (1, 2), (2, 1), (2, 2), (2, 3, 2), (3, 2)]
        shape = [(3,), (2, 3), (3, 4, 3), (3, 2, 3), (4, 3, 2, 4), (2, 2)]
        for s in shape:
            b = randint(0, 10, size=s)
            for r in reps:
                a = np.ones(r, b.dtype)
                large = tile(b, r)
                klarge = kron(a, b)
                assert_equal(large, klarge)
示例#8
0
 def test_basic(self):
     a = np.array([0, 1, 2])
     b = [[1, 2], [3, 4]]
     assert_equal(tile(a, 2), [0, 1, 2, 0, 1, 2])
     assert_equal(tile(a, (2, 2)), [[0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2]])
     assert_equal(tile(a, (1, 2)), [[0, 1, 2, 0, 1, 2]])
     assert_equal(tile(b, 2), [[1, 2, 1, 2], [3, 4, 3, 4]])
     assert_equal(tile(b, (2, 1)), [[1, 2], [3, 4], [1, 2], [3, 4]])
     assert_equal(tile(b, (2, 2)), [[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]])
示例#9
0
 def test_basic(self):
     a = np.array([0, 1, 2])
     b = [[1, 2], [3, 4]]
     assert_equal(tile(a, 2), [0, 1, 2, 0, 1, 2])
     assert_equal(tile(a, (2, 2)), [[0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2]])
     assert_equal(tile(a, (1, 2)), [[0, 1, 2, 0, 1, 2]])
     assert_equal(tile(b, 2), [[1, 2, 1, 2], [3, 4, 3, 4]])
     assert_equal(tile(b, (2, 1)), [[1, 2], [3, 4], [1, 2], [3, 4]])
     assert_equal(tile(b, (2, 2)), [[1, 2, 1, 2], [3, 4, 3, 4],
                                    [1, 2, 1, 2], [3, 4, 3, 4]])
示例#10
0
def classify(inX,dataSet,labels,k):
    dataSetSize = dataSet.shape[0]
    diffMat = tile(inX,(dataSetSize,1)) -dataSet    #   算距离
    print(diffMat)
    sqDiffMat = diffMat**2      
    sqDistances = sqDiffMat.sum(axis=1)             #
    distances = sqDistances**0.5                    #
    print(sqDistances)
    sortedDistIndicies = distances.argsort()
    classCount = {}
    for i in range(k):                              # 距离最小的k个点 
        voteIlabel = labels[sortedDistIndicies[i]]
        classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1
    sortedClassCount = sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)   # 排序
    print(sortedClassCount)
    return sortedClassCount[0][0]
示例#11
0
def knn(group, labels, test, k):
    tests = tile(test, (group.shape[0], 1))
    diff = group - tests
    diff_pow = diff * diff
    diff_sum = sum(diff_pow, axis=1)
    distance = diff_sum**0.5
    argsort = distance.argsort()
    print('distance:', distance)
    print('argsort:', argsort)
    classcount = {}
    for i in arange(k):
        label = labels[argsort[i]]
        print('label:' + label)
        classcount[label] = classcount.get(label, 0) + 1
    print(classcount)
    sortClasscount = sorted(classcount.items(), key=operator.itemgetter(1))
    print(sortClasscount)
    print('res:', sortClasscount[0][0])
示例#12
0
 def test_tile_one_repetition_on_array_gh4679(self):
     a = np.arange(5)
     b = tile(a, 1)
     b += 2
     assert_equal(a, np.arange(5))
示例#13
0
        val1[1][n] = strs[-2]
    else:
        res0 += np.array(line2array(strs, list_label))
        val0[0][n - 8] = strs[-3]
        val0[1][n - 8] = strs[-2]
    n = n + 1

print("res1:")
print(res1)
print("res0:")
print(res0)

add_1 = np.hstack(((np.ones([3, 5]) * 3), np.ones([3, 1]) * 2))  #拉普拉斯正则化
add_2 = np.ones([3, 6])

diff_0 = (res0 + add_2) / (tile(res0.sum(axis=0), (3, 1)) + add_1)
diff_1 = (res1 + add_2) / (tile(res1.sum(axis=0), (3, 1)) + add_1)
print("diff_0:")
print(diff_0)
print("diff_1:")
print(diff_1)
#--------------------↑前六列训练数据----------------------
list_test = ["青绿", "蜷缩", "浊响", "清晰", "凹陷", "硬滑"]
test_1 = line2array(list_test, list_label)
print("test:")
print(test_1)
#--------------------↑前六列测试数据----------------------
p_0_pre = diff_0 * test_1
print("前六列为'否'各概率:")
print(p_0_pre)
print("前六列为'是'各概率:")
示例#14
0
 def test_empty(self):
     a = np.array([[[]]])
     d = tile(a, (3, 2, 5)).shape
     assert_equal(d, (3, 2, 0))
示例#15
0
# coding:utf-8
"""
格式:tile(A,reps) 
* A:array_like 
*      输入的array 
* reps:array_like 
*       A沿各个维度重复的次数
"""
from numpy.lib.shape_base import tile

A = [1, 2]
print tile(A, 2)  # [1 2 1 2]
"""
[[1 2 1 2 1 2]
 [1 2 1 2 1 2]]
"""
# 理解 2,3这里2,3代表:  行的维度平铺2次, 列的维度 平铺3次. 最终得到 2行,6列的数组 (A是2个元素的数组* 3).
print tile(A, (2, 3))
示例#16
0
 def test_tile_one_repetition_on_array_gh4679(self):
     a = np.arange(5)
     b = tile(a, 1)
     b += 2
     assert_equal(a, np.arange(5))
示例#17
0
def getDistance(v, dataset):
    rowsize, columnsize = dataset.shape
    diffMat = tile(v, (rowsize, 1)) - dataset
    sqDiffMat = diffMat**2
    sqrtDiffMat = sqDiffMat.sum(axis=1)**0.5
    return sqrtDiffMat
示例#18
0
 def test_empty(self):
     a = np.array([[[]]])
     d = tile(a, (3, 2, 5)).shape
     assert_equal(d, (3, 2, 0))
示例#19
0
import numpy as np
from numpy.lib.shape_base import tile

if __name__ == '__main__':
    aa1 = np.array([[1, 2], [7, 8], [11, 12], [12, 12]])
    print aa1
    print aa1.shape
    print aa1[0]
    group = np.array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]])
    print group
    aa = (2, 4)
    bb = tile(aa, (4, 1))
    print aa1
    print bb
    cc = bb - aa1
    print cc
    dd = cc**2
    print 'dd is ' + dd
    ee = dd**0.5
    print ee

    print ee
    print ee.argsort()
    dd = ee.argsort()
    labels = ['A', 'B', 'C', 'D']

    print dd[0]
    voteIlabel = labels[dd[0]]