Julia is a language designed for high-level performance and can support interactive use as well. It has many descriptive datatypes and type-declarations can be used to solidify the programs. Julia is slowly climbing the ladder and gaining the interest of many Data Scientists and machine learning scientists today. It is comparatively faster than Python as it is designed to implement the math concepts like linear algebra and matrix representations. Excellent for numerical computation, this language has multiple dispatches for defining data types like numbers and arrays.
Arrays using Comprehensions
Julia arrays use square brackets([ ]) for list comprehensions just like Python or MATLAB. It consists of three kinds of arrays. Array comprehension is a very powerful way to construct an array. The resulting array depends on the type of data used while construction.
Syntax:
[expression for element = iterable]
For 1-D Arrays:
# Julia array using for loop twice = [] for i in 1:5 push!(twice, 2i) |
can also be written and will give the same output as
# Using Comprehension twice = [2x for x=1:5] |

For 2-D Arrays:
# Creating 2D array using comprehension u = [x + 2y for x in 1:5, y in 0:1] |

For 3-D Arrays:
# Creating 3D arrays using comprehension p = [x + 2y + 3z for x in 1:4, y in 0:1, z in 1:3] |

Arrays using Generators
This does not exactly return an array type data structure but a generator type data structure. It uses parentheses ‘( )’ instead of the square brackets as in list comprehensions. The syntax else is very similar to that of the above.
The object can be iterated to produce values when needed instead of allocating an array and storing them in advance. The series of data below are not allocated any memory unlike the examples above.
Syntax:
(expression for element = iterable)
For 1-D Arrays:
# Creating 1D Array using Generators j = (2x for x = 1:5) |

For 2-D Arrays:
# Creating 2D Arrays using Generators u = (x + 2y for x in 1:5, y in 0:1) |

For 3-D Arrays:
# Creating 3D arrays using Generators p = (x + 2y + 3z for x in 1:4, y in 0:1, z in 1:3) |

Recommended Posts:
- Creation of vectors in Julia - vect() Method
- Get all array elements with true values in Julia | Array findall() Method
- Get previous true value from a given array index in Julia | Array findprev() Method
- Reshaping array dimensions in Julia | Array reshape() Method
- Get index of last true value of array in Julia | Array findlast() Method
- Get index of first true value of array in Julia | Array findfirst() Method
- Get next true value from a given array index in Julia | Array findnext() Method
- Comprehensions in Python
- Scala | Sequence Comprehensions
- Nested List Comprehensions in Python
- Julia function keyword | Create user-defined functions in Julia
- Julia break Keyword | Exiting from a loop in Julia
- Getting last element of an array in Julia - last() Method
- Getting first element of an array in Julia - first() Method
- Searching in Array for a given element in Julia
- Julia end Keyword | Marking end of blocks in Julia
- Reshaping array as a vector in Julia - vec() Method
- Get dimensions of array in Julia - ndims() Method
- Accessing every row and column of array in Julia - colon() Operator
- Get number of elements of array in Julia - length() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

