本文整理汇总了Python中Matrix.Matrix.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.get_data方法的具体用法?Python Matrix.get_data怎么用?Python Matrix.get_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.get_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: power
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import get_data [as 别名]
def power(self, iterations, mat, estimate):
r = 1
k = 0
m = iterations
y = estimate
x = mat.multiply(y)
while r > .001 and k < m:
max_x = x.find_max()
x.scaler(1 / max_x)
y = Matrix(x.get_data())
x = mat.multiply(y)
temp = Matrix(y.get_data())
temp.transpose()
a = temp.multiply(x).get_data()[0][0]
b = temp.multiply(y).get_data()[0][0]
mu = a / b
r = Matrix(y.get_data())
r.scaler(mu)
r = r.subtract(x)
r = r.find_max()
k += 1
y.scaler(1 / mu)
return mu, mat.trace() - mu, y
示例2: __init__
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import get_data [as 别名]
class Points:
def __init__(self):
self.data = []
self.points = {}
self.set_points()
self.temp_dist = []
self.distance = Matrix([[0]])
self.set_distances()
self.random_bins = [0] * 100
self.random_total = 0
self.random_squares = 0
self.random_count = 0
self.random_best_dist = self.distance.find_max() * len(self.distance.get_data())
self.random_best_trip = []
self.genetic_best_dist = self.distance.find_max() * len(self.distance.get_data())
self.genetic_best_trip = []
self.genetic_bins = [0] * 100
# Return Matrix that is composed of the distances between points being tested
def get_distances(self):
return self.distance
# Return random search bins
def get_random_bins(self):
return self.random_bins
# Return the summation of all trips tested in the random search
def get_random_total(self):
return self.random_total
# Return the summation of all trips squared
def get_random_squares(self):
return self.random_squares
# Return the number of trips tested
def get_random_count(self):
return self.random_count
# Print the bins for the random search
def print_random_bins(self):
print('Random bins')
for i in range(len(self.random_bins)):
print(self.random_bins[i])
# Print the bins for the genetic search
def print_genetic_bins(self):
print('Genetic bins')
for i in range(len(self.genetic_bins)):
print(self.genetic_bins[i])
# Get points from a file
def set_points(self):
count = 1
temp = []
filename = open('points.txt', 'r')
for line in filename:
row = line.strip()
temp.append(row)
for i in range(0, len(temp)):
self.data.append(temp[i].split())
for i in self.data:
mat = Matrix([[float(i[0]), float(i[1])]])
self.points[count] = mat
count += 1
# Create a matrix of each points distance from the other points
def set_distances(self):
for i in range(1, 15):
temp = []
for j in range(1, 15):
x1 = self.points[i].get_data()[0][0]
y1 = self.points[i].get_data()[0][1]
x2 = self.points[j].get_data()[0][0]
y2 = self.points[j].get_data()[0][1]
temp.append(math.hypot(x2 - x1, y2 - y1))
self.temp_dist.append(temp)
self.distance = Matrix(self.temp_dist)
# Create a random trip, including all cities in TSP problem
def random_trip(self):
dist = random.sample(range(14), 14)
for i in range(len(dist)):
dist[i] += 1
return dist
# Performs the random search of finding a possible solution
# Takes in the number of random trips to evaluate
# Also returns the best trip and the cost of the best trip
def random_search(self, iterations):
self.random_count = iterations
for i in range(iterations):
trip = self.random_trip()
dist = test.calculate_distance(trip)
if dist < self.random_best_dist:
self.random_best_dist = dist
self.random_best_trip = trip
self.random_total += dist
self.random_squares += dist * dist
index = int((dist - 20) / -0.2)
#.........这里部分代码省略.........