python-3.x - 寻找N维等边三角形的第三个顶点
问题描述
给定两个向量 X 和 Y,其中每个向量的元素数为 5。找到满足 : ||XV||=||YV||=||XY|| 的 V 向量
(X,Y,V) 是等边三角形的顶点。我尝试了以下方法:要获得垂直于 A 和 B 的向量 V :
import NumPy as np
# Example vectors
x = [ 0.93937874, 0.05568767, -2.05847484, -1.15965884, -0.34035054]
y = [-0.45921145, -0.55653187, 0.6027685, 0.13113272, -1.2176953 ]
# convert those vectors to a matrix to apply SVD (sure there is a shorter code to do so)
A_list=[]
A_list.append(x)
A_list.append(y)
A=np.array(A_list) # A is a Numpy matrix
u,s,vh=np.linalg.svd(A)
v=vh[-1:1]
从这里开始,我该怎么办?假设我到目前为止所做的是正确的
解决方案
我不确定您的问题,但为了计算 SVD,您需要2D
数组,因此我将您的代码更改如下:
import numpy as np
# Example vectors
x = [ 0.93937874, 0.05568767, -2.05847484, -1.15965884, -0.34035054]
y = [-0.45921145, -0.55653187, 0.6027685, 0.13113272, -1.2176953 ]
# convert those vectors to a matrix to apply SVD (sure there is a shorter code to do so)
A_list=[]
for i in range(len(x)):
A_list.append(x[i])
A_list.append(y[i])
A_list = np.reshape(A_list, (-1, 2))
U, s, VT = np.linalg.svd(A_list)
print("U:")
print(U)
print("s:")
print(s)
print("VT:")
print(VT)
print("1D of VT:")
print(VT.ravel())
输出:
U:
[[-0.38968619 -0.11523678 0.80252406 0.43581711 0.02972783]
[-0.0822262 -0.37007052 0.01506547 -0.13669766 -0.91508111]
[ 0.80885241 -0.02438814 0.52870487 -0.25569671 -0.01591684]
[ 0.43239026 -0.15678279 -0.26526405 0.84082071 -0.1054198 ]
[-0.01341535 -0.90807085 -0.07638266 -0.13790184 0.38778362]]
s:
[2.65146474 1.39181336]
VT:
[[-0.95513377 0.29617476]
[ 0.29617476 0.95513377]]
1D of VT:
[-0.95513377 0.29617476 0.29617476 0.95513377]
这对你有帮助吗?
推荐阅读
- node.js - 找不到模块'sqlite3'
- php - Laravel 中的 Slack 通知 - to() 函数什么都不做?
- python - 如何使用 discord.py 获取服务器 ID?
- flutter - 如何将 showdatepicker + showtimepicker 结果与当前日期 (datetime.now()) 进行比较
- javascript - 对象数组首先显示具有指定键的对象
- corda - Corda 节点驱动程序不拾取自定义序列化程序
- elixir - 如何正确使用mix phx.gen.html?收到错误:“(混合)预期架构“帖子”是有效的模块名称”
- javafx - 为什么我的 javafx 标签在更改后不显示?
- python - 如何在 Python 中创建 XLSM 文件
- python - 跳过 Python 预提交单元测试