python - 循环后小数消失
问题描述
我目前正在做一些学校练习,但总是遇到麻烦。我正在围绕中心点旋转和缩放矢量集。看起来我很接近,因为我的数字真的很接近答案,但它们是四舍五入的。我试过让所有东西都浮动(通过早期和晚期确定它们,但也通过循环),但它们仍然消失。我的代码如下所示:
import numpy as np
import math
def rotateScale(coordinates, center, theta, scale):
new=np.copy(coordinates)
new[1,:]=0
new[0,:]=0
for n in range(len(coordinates[0,:])):
#for n in range(1):
for i in range(len(new[:,n])):
new[i,n]=float(new[i,n])
matrix=np.reshape([math.cos(theta),-1*math.sin(theta),math.sin(theta),math.cos(theta)],[2,2])
matrix2=coordinates[:,n]-center
new[:,n]=np.dot(matrix,matrix2)*scale+center
newCoordinates=new
return newCoordinates
print(rotateScale(np.array([[1,3,3,4,7,6,1],[1,1,2,3,3,5,5]]), np.array([5,2]), -math.pi/3, 2))
我的输出是这样的
[[ 0 1 2 5 8 11 6]
[ 7 4 5 4 0 3 11]]
但它应该是这样的:
[[ -0.73205081 1.26794919 3. 5.73205081 8.73205081 11.19615242 6.19615242]
[ 7.92820323 4.46410162 5.46410162 4.73205081 -0.46410162 3.26794919 11.92820323]]
有谁知道发生了什么?:)
解决方案
推荐阅读
- javascript - 将图像/SVG/徽标放在文本的上角(使用 react.js)
- javascript - 调整画布大小时如何将 Fabric.js 画布中的剪辑路径居中并将对象保持在剪辑路径中的同一位置
- mysql - 尝试删除列时 Azure SQL DacPac 部署失败,即使为 SqlPackage.exe 设置了 /p:BlockOnPossibleDataLoss=False
- c# - 将 SQL 中的滞后、分区依据转换为 LINQ Lambda
- c - 与 Apple Silicon M1 一致
- reactjs - 如何在下一个 js 静态生成中停止缓存使用本地 json 文件的页面?
- youtube-analytics-api - 通过api获取youtube交易收入
- javascript - 没有调用 Angular API 调用
- android-studio - 调试时将设备设置为默认值
- jquery - jQuery 和“水上漂浮”效果