Julia:将1x1数组从内部乘积转换为数字 [英] Julia: convert 1x1 array from inner product to number

查看:101
本文介绍了Julia:将1x1数组从内部乘积转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从内积运算中获取数字而不是从1x1数组中获取数字的最佳方法是什么.有没有比这更好的方法了?

What is the best way to get a number out of an inner product operation, rather than a 1x1 array. Is there a better way than this:

([1 2 3]*[4 5 6]')[1]

推荐答案

如果可能的话,我不会手动制作内部产品,而是使用dot,即

If possible, I wouldn't do the inner product manually, I'd use dot, i.e.

 dot([1, 2, 3], [4, 5, 6])

我注意到您实际上并没有向量,而是有1x3个矩阵(行),因此,如果这确实是您所需要的,则必须首先vec个它们,这是一个有点不愉快:

I've noticed that you don't actually have vectors there though, instead you have 1x3 matrices (rows), so if thats really what you have you'd have to vec them first, which is a bit unpleasant:

dot(vec([1 2 3]), vec([4 5 6]))

或者,一个人可以做

 sum([1 2 3].*[4 5 6])

这与尺寸无关.

这篇关于Julia:将1x1数组从内部乘积转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆