4 Working with collections in Julia

 

This chapter covers

  • Working with arrays
  • Using dictionaries to handle key-value mappings
  • Handling immutable collection types: tuples and named tuples

In chapters 2 and 3, you learned basic elements of the Julia language. We have mostly used scalar types (like numbers) in all the examples. However, in data science, you will typically work with data collections, groupings of a variable number of data items. One collection type already introduced in chapter 2 is a vector.

In this chapter, you will learn how to use several fundamental collections that are most used in practical scenarios: arrays, dictionaries, tuples, and named tuples.

4.1 Working with arrays

In this section, you will learn the basics of working with arrays in Julia: their creation, indexing into arrays, and the most common operations you can expect to perform with them. Arrays are commonly used collections in data science. Most machine learning algorithms expect data stored in arrays as their inputs. In Julia (as opposed to, for example, Python), arrays are part of the language specification, so they are equipped with a convenient syntax. Working with them requires learning only one set of rules, and they are fast.

4.1.1 Getting the data into a matrix

4.1.2 Computing basic statistics of the data stored in a matrix

4.1.3 Indexing into arrays

4.1.4 Performance considerations of copying vs. making a view

4.1.5 Calculating correlations between variables

4.1.6 Fitting a linear regression

4.1.7 Plotting the Anscombe’s quartet data

4.2 Mapping key-value pairs with dictionaries

4.3 Structuring your data by using named tuples

4.3.1 Defining named tuples and accessing their contents

4.3.2 Analyzing Anscombe’s quartet data stored in a named tuple

4.3.3 Understanding composite types and mutability of values in Julia

Summary