Rahul Kalwar
Rahul Kalwar

Reputation: 157

Can any one suggest what ".>" do in julia lang

Can any one suggest what .> will do in below code. I have tried to run without . and it failed

array6[:, 1] .> 12

Upvotes: 1

Views: 53

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69839

array6[:, 1] .> 12

is the same as

broadcast(>, array6[:, 1], 12)

You can check the details what broadcast does in its docstring.

You can also have a look at https://docs.julialang.org/en/latest/manual/arrays/#Array-and-Vectorized-Operators-and-Functions-1 and https://docs.julialang.org/en/latest/manual/arrays/#Broadcasting-1 sections (including the links therein) in the Julia manual, which explain how and why such operations work.

Let me just give a short comment. You try to compare using > a vector (one column of a matrix array6) and a scalar (12). Such an operation is not well defined in mathematics by default, so Julia does not allow it either.

What broadcasting does in this case is that it spreads the object with a lower dimensionality (a scalar, which has dimension 0, which you can check by writing ndims(12)) to the dimension of the object with a higher dimensionality (a vector in this case, which has dimension 1, which you can check by writing ndims(array6[:, 1])). Spreading is performed by just repeating the value 12 as many times as needed in the target dimension to make the sizes of both objects match (technically what should match after spreading is what is returned by axes function). Then if you have two objects of the same size a function > is applied to each matching elements of both objects.

Upvotes: 3

Related Questions