Introducere în array-uri

Introducere în Julia

James Fulton

Climate informatics researcher

Ce este un array?

# Store run times with many variables
runtime1 = 33.1
runtime2 = 32.7
runtime3 = 34.2
runtime4 = 31.9
# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]
  • Listă de valori
  • Delimitată de [ ]
  • Cu , între valori
Introducere în Julia

Array-uri vs. vectori vs. matrice

# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]

println(typeof(runtimes))
Vector{Float64}
Introducere în Julia

Array-uri vs. vectori vs. matrice

Imaginea prezintă un vector ca o linie unidimensională de valori.

Introducere în Julia

Array-uri vs. vectori vs. matrice

Imaginea prezintă o matrice ca o grilă bidimensională de valori.

Introducere în Julia

Array-uri vs. vectori vs. matrice

Imaginea prezintă un array ca o grilă multidimensională de valori.

Introducere în Julia

Tipuri de date în array-uri

# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]

println(typeof(runtimes))
Vector{Float64}
Introducere în Julia

Tipuri de date în array-uri

# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]

println(eltype(runtimes))
Float64
Introducere în Julia

Tipuri de date în array-uri

# Store integers in array
number_of_customers = [11, 19, 31, 27]

println(typeof(number_of_customers))
Vector{Int64}
# Store strings in array
names = ["Amit", "Barbara", "Carlos"]

println(typeof(names))
Vector{String}
# Store characters in array
grades = ['A', 'B', 'B', 'A']

println(typeof(grades))
Vector{Char}
# Store booleans in array
correct_answers = [true, false, true]

println(typeof(correct_answers))
Vector{Bool}
Introducere în Julia

Tipuri de date mixte

# Store multiple types in array
#        string   bool  int char float
items = ["James", true, 10, 'B', -20.3]

println(typeof(items))
Vector{Any}
Introducere în Julia

Tipuri de date mixte

# Store array of item names
item_names = ["chalk", "cheese", "eggs", "ham"]

# Store array of item prices
item_prices = [2.30, 3.50, 4.25, 2.00]

println(typeof(item_names))
println(typeof(item_prices))
Vector{String}
Vector{Float64}
Introducere în Julia

Indexarea array-urilor

# Index:         1        2        3       4
item_names = ["chalk", "cheese", "eggs", "ham"]

# Index:         1     2     3     4
item_prices = [2.30, 3.50, 4.25, 2.00]

println(item_names[1])
println(item_prices[1])
chalk
2.30
Introducere în Julia

Indexarea array-urilor

# Index:         1        2        3       4
item_names = ["chalk", "cheese", "eggs", "ham"]

# Index:         1     2     3     4
item_prices = [2.30, 3.50, 4.25, 2.00]

println(item_names[end])
println(item_prices[end])
ham
2.00
Introducere în Julia

Indexarea array-urilor

# Index:         1        2        3       4
item_names = ["chalk", "cheese", "eggs", "ham"]

# Index:         1     2     3     4
item_prices = [2.30, 3.50, 4.25, 2.00]

println(item_names[end-1])
println(item_prices[end-1])
eggs
4.25
Introducere în Julia

Slice-uirea array-urilor

# Index:         1        2        3       4
item_names = ["chalk", "cheese", "eggs", "ham"]

# Index:         1     2     3     4
item_prices = [2.30, 3.50, 4.25, 2.00]

println(item_names[1:2])
["chalk", "cheese"]
Introducere în Julia

Să exersăm!

Introducere în Julia

Preparing Video For Download...