Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: convert 1x1 array from inner product to number

Tags:

julia

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]
like image 364
Rob Donnelly Avatar asked Mar 04 '15 01:03

Rob Donnelly


1 Answers

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

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

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]))

Alternatively, one could do

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

which doesn't care about the dimensions.

like image 55
IainDunning Avatar answered Oct 17 '22 07:10

IainDunning