updates
This commit is contained in:
@@ -359,9 +359,12 @@ fibs = [1, 1, 2, 3, 5, 8, 13]
|
||||
Later we will discuss different ways to modify the values of a vector to create new ones, similar to how scalar multiplication does.
|
||||
|
||||
|
||||
As mentioned, vectors in `Julia` are comprised of elements of a similar type, but the type is not limited to numeric values. Some examples:,
|
||||
As mentioned, vectors in `Julia` are comprised of elements of a similar type, but the type is not limited to numeric values. Some examples:
|
||||
|
||||
* a vector of strings might be useful for text processing, For example, the `WordTokenizers.jl` package takes text and produces tokens from the words.
|
||||
|
||||
* a vector of Boolean values can naturally arise and is widely used within Julia's `DataFrames.jl` package.
|
||||
|
||||
* some applications are even naturally represented in terms of vectors of vectors (such as happens when plotting a collection points).
|
||||
|
||||
|
||||
@@ -378,7 +381,7 @@ Look at the output of these two vectors, in particular how the underlying type o
|
||||
|
||||
|
||||
|
||||
Finally, we mention that if `Julia` has values of different types it will promote them to a common type if possible. Here we combine three types of numbers, and see that each is promoted to `Float64`:
|
||||
Finally, we mention that if `Julia` has values of different types it will promote them to a common type, as possible. Here we combine three types of numbers, and see that each is promoted to `Float64`:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -415,6 +418,8 @@ vs[2]
|
||||
|
||||
The last value of a vector is usually denoted by $v_n$. In `Julia`, the `length` function will return $n$, the number of items in the container. So `v[length(v)]` will refer to the last component. However, the special keyword `end` will do so as well, when put into the context of indexing. So `v[end]` is more idiomatic. (Similarly, there is a `begin` keyword that is useful when the vector is not $1$-based, as is typical but not mandatory.)
|
||||
|
||||
The functions `first` and `last` refer to the first and last components of a collection. An additional argument can be specified to take the first (or last) $n$ components. The function `only` will return the only component of a vector, if it has length $1$ and error otherwise.
|
||||
|
||||
|
||||
:::{.callout-note}
|
||||
## More on indexing
|
||||
@@ -837,7 +842,7 @@ d["two"]
|
||||
|
||||
Named tuples are associative arrays where the keys are restricted to symbols. There are other types of associative arrays, specialized cases of the `AbstractDict` type with performance benefits for specific use cases. In these notes, dictionaries appear as output in some function calls.
|
||||
|
||||
Unlike vectors and tuples, named tuples and dictionaries are not currently supported by broadcasting. This causes no loss in usefulness, as the values can easily be iterated over, but the convenience of the dot notation is lost.
|
||||
Unlike vectors and tuples, dictionaries are not currently supported by broadcasting. This causes no loss in usefulness, as the values can easily be iterated over, but the convenience of the dot notation is lost.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user