本文整理汇总了Python中Matrix类的典型用法代码示例。如果您正苦于以下问题:Python Matrix类的具体用法?Python Matrix怎么用?Python Matrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_axis
def show_axis(tf, color, os):
import Matrix
axis, axis_point, angle, axis_shift = Matrix.axis_center_angle_shift(tf)
if angle < 0.1:
raise CommandError, 'Rotation angle is near zero (%g degrees)' % angle
have_box, box = os.bbox()
if not have_box:
# TODO: Chimera does not provide bounding box of full model.
raise CommandError, 'First model must be visible to show axis'
axis_center = Matrix.project_to_axis(box.center().data(), axis, axis_point)
axis_length = max((box.urb - box.llf).data())
hl = 0.5*axis_length
ap1 = map(lambda a,b: a-hl*b, axis_center, axis)
ap2 = map(lambda a,b: a+hl*b, axis_center, axis)
from VolumePath import Marker_Set, Link
from VolumePath.markerset import chimera_color
m = Marker_Set('rotation axis')
mm = m.marker_model()
mm.openState.xform = os.xform
if color:
mm.color = chimera_color(color)
radius = 0.025 * axis_length
m1 = m.place_marker(ap1, None, radius)
m2 = m.place_marker(ap2, None, radius)
Link(m1, m2, None, radius)
示例2: rotation_axis
def rotation_axis(operation, model1, model2,
showAxis = True, showSlabs = False, color = None):
os1 = set([m.openState for m in model1])
os2 = set([m.openState for m in model2])
if len(os1) != 1:
raise CommandError, 'First model spec names %d models, require 1' % len(os1)
if len(os2) != 1:
raise CommandError, 'Second model spec names %d models, require 1' % len(os2)
os1 = os1.pop()
os2 = os2.pop()
xf = os1.xform.inverse()
xf.multiply(os2.xform)
import Matrix
tf = Matrix.xform_matrix(xf)
message = ('Position of %s (%s) relative to %s (%s) coordinates:\n'
% (model2[0].name, model2[0].oslIdent(),
model1[0].name, model1[0].oslIdent()))
message += Matrix.transformation_description(tf)
from chimera import replyobj
replyobj.info(message)
from chimera import MaterialColor
if isinstance(color, MaterialColor):
color = color.rgba()
elif not color is None:
raise CommandError, 'Unknown color "%s"' % str(color)
if showAxis:
show_axis(tf, color, os1)
if showSlabs:
show_slabs(xf, color, os1)
示例3: read_graph
def read_graph(file_path="data/amazon_m_0.edgelist"):
matrices = []
a_tuples = []
d_tuples = []
l = 0
prev_i = 0
with open(file_path, "r", encoding="utf8") as file:
for line in file:
l += 1
if l > 2:
row = line.split("\n")[0].split(" ")[:2]
i = int(row[0])
j = int(row[1])
v = random.choice([-1, 1])
if prev_i < i:
v_ = [item[2] for item in a_tuples if item[0] == prev_i]
d_tuples.append((prev_i, prev_i, sum(v_)))
prev_i = i
a_tuples.append((i, j, v))
v_ = sum([item[2] for item in a_tuples if item[0] == i])
d_tuples.append((i, i, v_))
r, c, v = Matrix.tuple2csr(a_tuples)
a = Matrix().set(r, c, v)
r, c, v = Matrix.tuple2csr(d_tuples)
d = Matrix().set(r, c, v)
matrices.append(d.sub(a))
return matrices
示例4: testReadCSV
def testReadCSV(self):
'''Tests if a matrix can be properly initialised from a csv file'''
#Test can read csv files produce by the class itself
string = self.matrix.csvRepresentation()
file = open('temp', 'w')
file.write(string)
file.close()
matrix = Matrix.matrixFromCSVFile('temp')
self.assertEqual(matrix, self.matrix)
os.remove('temp')
#Test initialisation for a csv file not in the same format
#as the one created by the Matrix class
file = open('temp', 'w')
file.write(testCSVString)
file.close()
matrix = Matrix.matrixFromCSVFile('temp')
self.assertEqual(matrix, self.matrix)
#Test it works when told not to read header
file = open('temp', 'w')
file.write(testCSVString2)
file.close()
matrix = Matrix.matrixFromCSVFile(filename='temp', readHeaders=False)
matrix.setColumnHeaders(["Header1", "Header2"])
self.assertEqual(matrix, self.matrix)
#Clean up
os.remove('temp')
示例5: setTurretRotation
def setTurretRotation (self, t_):
t = t_
if abs (t) > self.turretrotspeed:
t = self.turretrotspeed * t / abs (t)
self.turretTheta += t
m = Matrix.translate (-self.pos.x (), -self.pos.y (), 0) * Matrix.rotate (0, -t, 0) * Matrix.translate (self.pos.x (), self.pos.y (), 0)
self.turret.transform (m)
示例6: transform_ellipsoid
def transform_ellipsoid(axes, center, xform):
import Matrix as m
tf = m.xform_matrix(xform)
axes = m.apply_matrix_without_translation(tf, axes)
center = m.apply_matrix(tf, center)
return axes, center
示例7: compute
def compute(self):
a = self.get_input("Array")
try:
mat = sparse.csc_matrix(a.get_array())
out_mat = Matrix()
out_mat.set_matrix(mat)
self.set_output("Output Matrix", out_mat)
except:
raise ModuleError("Could not convert input array to matrix")
示例8: set_outputs
def set_outputs(self, results):
try:
out = Matrix()
out.set_matrix(sparse.csc_matrix(results[0]))
self.setResult("Matrix Output", out)
except:
pass
out_ar = NDArray()
out_ar.set_array(numpy.array(results[0]))
self.setResult("Array Output", out_ar)
示例9: show_cumulative_transform
def show_cumulative_transform(self, m):
from chimera import Xform
mxf = getattr(m, 'applied_xform', Xform())
import Matrix
tf = Matrix.xform_matrix(mxf)
angles = Matrix.euler_angles(tf)
shift = mxf.getTranslation().data()
text = ('Cumulative:\n' +
' Euler angles %.5g %.5g %.5g\n' % angles +
' Shift: %.5g %.5g %.5g' % shift)
self.cumulative['text'] = text
示例10: graph_event_cb
def graph_event_cb(event, v1=v1, axis=axis, center=center, cur_angle = [0]):
if not event.button is None:
angle = event.xdata
if angle is None:
angle = 0 # Click outside graph bounds
import Matrix
tf = Matrix.rotation_transform(axis, angle-cur_angle[0], center)
xf = Matrix.chimera_xform(tf)
v1.openState.localXform(xf)
cur_angle[0] = angle
ax.cur_position.set_xdata((angle,angle))
ax.figure.canvas.draw()
示例11: print_axes
def print_axes(axes, d2, elen, name, xform = None):
if xform:
import Matrix as m
axes = m.apply_matrix_without_translation(m.xform_matrix(xform), axes)
from math import sqrt
paxes = ['\tv%d = %6.3f %6.3f %6.3f %s = %6.3f r%d = %6.3f' %
(a+1, axes[a][0], axes[a][1], axes[a][2],
('a','b','c')[a], elen[a], a+1, sqrt(d2[a]))
for a in range(3)]
from chimera.replyobj import info
info('Inertia axes for %s\n%s\n' % (name, '\n'.join(paxes)))
from Accelerators.standard_accelerators import show_reply_log
show_reply_log()
示例12: texture_surface_piece
def texture_surface_piece(p, t, txf, border_color, offset = 0):
p.textureId = t.texture_id()
p.useTextureTransparency = ('a' in t.color_mode)
p.textureModulationColor = t.modulation_rgba()
p.textureBorderColor = border_color
va = offset_vertices(p, offset)
s2tc = t.texture_matrix()
p2s = p.model.openState.xform
p2s.premultiply(txf.inverse())
import Matrix
p2tc = Matrix.multiply_matrices(s2tc, Matrix.xform_matrix(p2s))
import _contour
_contour.affine_transform_vertices(va, p2tc)
p.textureCoordinates = va
p.using_surface_coloring = True
示例13: AddParseResults
def AddParseResults(self, tokenList, POSList, conTree, depTokenPos, depGraph):
try:
self.parseResult = Matrix.matrix(tokenList)
self.parseResult.add_row(self.__alignTokensToOrigSent(tokenList))
self.parseResult.add_row(POSList)
except:
print >> sys.stderr, "token"
raise
# conTree -> nltk.tree.ParentedTree
# parseResut[CON] row contains treepositions of the leaves
try:
self.conTree = conTree
self.parseResult.add_row(conTree.treepositions('leaves'))
except:
print >> sys.stderr, "con"
raise
# depGraph -> pygraph.classes.digraph
# parseResult[DEP] row contains identifiers of the leaves
try:
self.depGraph = depGraph
self.parseResult.add_row(self.__GenerateConMatchingDep(depTokenPos))
except:
print >> sys.stderr, "dep"
raise
示例14: save
def save(self, name):
xlow = min(x for x, y in self.jobs.board.blocks)
xhigh = max(x for x, y in self.jobs.board.blocks)
ylow = min(y for x, y in self.jobs.board.blocks)
yhigh = max(y for x, y in self.jobs.board.blocks)
matrix = [
[(x, y) in self.jobs.board.blocks for x in xrange(xlow, xhigh+1)]
for y in xrange(ylow, yhigh+1)
]
Log.log("Created new tetromino, displaying below")
Matrix.put(matrix)
Save.saveTetromino(self.color, name, matrix)
Shared.tetrominos = Load.loadTetrominos()
return True
示例15: __init__
def __init__(self):
self.numRows = 18
self.numColumns = 63
self.locMatrix = Matrix(self.numColumns,self.numRows)
self.componentList = []
self.rails= [0 , 2.5 , 2.5 , 5] #voltage rails. bottom to top. y = 17 16 1 0
self.initializeLocations() #assigns Location objects to each coordinate
self.nodeCreation() #assigns functional Nodes to proper Locations
self.detailLocations() #sets power rails and display flags