简体   繁体   English

在np中旋转点列表的惯用方式是什么?

[英]What's the idiomatic way to rotate a list of points in np?

Here's a code I use to rotate a 2D vector by 100 degrees: 这是我用来将2D向量旋转100度的代码:

theta = np.deg2rad(100)
c, s = np.cos(theta), np.sin(theta)
R = np.matrix([[c, -s], [s, c]])
V = np.transpose(np.matrix([[1., 1.]]))
Z = np.matmul(R, V)

Is there a built in function for that in numpy? 在numpy中有一个内置函数吗?

I'd consider what you did as idiomatic. 我认为您的做法是惯用的。 If you want to be fancy you can use scipy . 如果想花哨,可以使用scipy

Avoid numpy.matrix, use regular arrays and array.dot(another). 避免使用numpy.matrix,使用常规数组和array.dot(another)。

In case you are interested in fixed size small vectors I would hardcode the result of the matrix operations and leave it dependent on the cos() and sin(). 如果您对固定大小的小向量感兴趣,我将对矩阵运算的结果进行硬编码,并使其取决于cos()和sin()。 If the matrix are small but a push with the math would be welcome I recommend you to try wxMaxima to get an analytical result to hardcode. 如果矩阵很小,但是欢迎使用数学运算,我建议您尝试使用wxMaxima以获得硬编码的分析结果。 On the other hand, if this is an example targeting bigger vectors I would follow Mihai's suggestion and go for scipy. 另一方面,如果这是针对较大向量的示例,那么我将遵循Mihai的建议并进行研究。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python中调用函数列表的惯用方法是什么? - What is the idiomatic way of invoking a list of functions in Python? 增加 Python 新 integer 类型的惯用方法是什么? - What's the idiomatic way to increment a Python new integer type? 在Python中为字典类型实现堆栈的最惯用的方法是什么? - What's the most idiomatic way to implement a stack for `dictionary` type in `Python`? 伪造__hash __()为dicts的惯用方法是什么? - What's the idiomatic way to fake __hash__() for dicts? 在pandas中执行聚合和重命名操作的惯用方法是什么? - What's the idiomatic way to perform an aggregate and rename operation in pandas 通过坐标索引对象列表的最惯用方法是什么 - What is the most idiomatic way to index a list of objects by coordinates 除了月底之外,将所有值设置为 NaN 的最惯用的方法是什么? - What's the most idiomatic way to set all values to NaN except the end of the month? 从文件创建输入变量的N个排列的PCollection的最惯用的方法是什么? - What's the most idiomatic way to create a PCollection of N permutations of an input variable from file? 在 numpy 中获得 2d arrays 的行相等的简洁/惯用方法是什么? - What's concise/idiomatic way to get row-wise equality of 2d arrays in numpy? 在flask项目中,创建应用程序后定义sql模型的惯用方式是什么? - In a flask project, what's an idiomatic way to define sql models after the app has been created?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM