Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vectorizing Dot before or after the Function Name?

Tags:

julia

I can vectorize a function using the dot notation:

a = Vector(0:10) .* 4 

As in plenty of examples I read the dot comes prior to the asterisk. However, this does not work in the following case:

Complex.(a,a)

Here the dot suddenly goes behind the function name.

Is this intended? And is there a rule?

like image 873
Georgery Avatar asked Apr 13 '20 07:04

Georgery


1 Answers

For functions, the dot always goes behind the function name.

For operators, like * or + for example, the dot goes before the operator. However, you can enclose the operator in parentheses and suffix the dot.

To make this difference even more explicit, consider this example where we apply "multiply" with function call syntax:

x = rand(2,2)
sqrt.(x)
.*(x,x)
(*).(x,x)
x .* x

The last three commands all do the same thing.

See the corresponding sections of the Julia documentation for more: Dot Syntax for Vectorizing Functions and Vectorized "dot" operators.

like image 191
carstenbauer Avatar answered Nov 10 '22 11:11

carstenbauer