如何使朱莉娅矩阵的列标准化
给定一个尺寸m,n的矩阵a,如何通过朱莉娅中的某个函数或其他过程使该矩阵的列标准化(目标是将列正常化,以使我们的新矩阵具有长度为1的列)?
Given a matrix A of dimensions m,n, how would one normalize the columns of that matrix by some function or other process in Julia (the goal would be to normalize the columns of A so that our new matrix has columns of length 1)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Mapslices
似乎在性能方面存在一些问题。在我的计算机(和v1.7.2)上,这是一个更快的速度:这是一个就地版本(因为
everycol
创建视图),它仍然更快(但仍然分配一点): ,某些比
映射
的循环版本的5x3矩阵:edit:添加了一个单线分配:
这不分配任何内容,与
归一化!。
是, foreach 没有返回任何内容,这使得在不需要输出的情况下它有用。mapslices
seems to have some issues with performance. On my computer (and v1.7.2) this is 20x faster:This is an in-place version (because
eachcol
creates views), which is faster still (but still allocates a bit):And, finally, some loop versions that are 40-70x faster than
mapslices
for the 5x3 matrix:Edit: Added a one-liner with zero allocations:
The reason this does not allocate anything, unlike
normalize!.
, is thatforeach
doesn't return anything, which makes it useful in cases where output is not needed.如果您想要一个新矩阵,则
mapslices
可能是您想要的:If you want a new matrix then
mapslices
is probably what you want:如果按长度1,您的意思是与Norm 1一样,这可能会起作用
,尽管我不知道有更好的解决方案!
If by length 1 you mean like with norm 1 maybe this could work
Though there are likely better solutions I don't know!