Related Articles

Related Articles

Creating a similar type of array in Julia – similar() Method
  • Last Updated : 01 Apr, 2020

The similar() is an inbuilt function in julia which is used to create an uninitialized mutable array with the given element type and size, based upon the given source array.

Syntax:
similar(array, element_type=eltype(array), dims=size(array))

Parameters:

  • array: Specified arrays.
  • element_type: Specified type of elements.
  • dims=size(array): Specified size of elements.

Returns: It returns an uninitialized mutable array with the given element type and size.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate
# the use of Array similar() method
  
# Getting an uninitialized mutable array
# with the given element type and size
A = [1, 2, 3, 4];
similar(A, 2, 4)
similar(2:8)
similar(2:8, 1)
similar(2:8, 1, 4)

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate
# the use of Array similar() method
  
# Getting an uninitialized mutable array
# with the given element type and size
println(similar(trues(2, 6), 3))
println(similar(falses(5), 1, 3))

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :