代码拉取完成,页面将自动刷新
import numpy as np
def read_matrix(path, astype=np.float64):
""" Reads a file containing a matrix where each line represents a point
and each point is tab or space separated. * are replaced with -1.
:param path: path to the file
:parama astype: type to cast the numbers. Default: np.float64
:returns: array of array of numbers
"""
with open(path, 'r') as f:
arr = []
for line in f:
arr.append([(token if token != '*' else -1)
for token in line.strip().split()])
return np.asarray(arr).astype(astype)
def cart2hom(arr):
""" Convert catesian to homogenous points by appending a row of 1s
:param arr: array of shape (num_dimension x num_points)
:returns: array of shape ((num_dimension+1) x num_points)
"""
if arr.ndim == 1:
return np.hstack([arr, 1])
return np.asarray(np.vstack([arr, np.ones(arr.shape[1])]))
def hom2cart(arr):
""" Convert homogenous to catesian by dividing each row by the last row
:param arr: array of shape (num_dimension x num_points)
:returns: array of shape ((num_dimension-1) x num_points) iff d > 1
"""
# arr has shape: dimensions x num_points
num_rows = len(arr)
if num_rows == 1 or arr.ndim == 1:
return arr
return np.asarray(arr[:num_rows - 1] / arr[num_rows - 1])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。