With this command we can see the array's [shape]({{ page.root }}/reference/#shape):

With the following command, we can see the array's [shape]({{ page.root }}/reference/#shape):

~~~

~~~

print(data.shape)

print(data.shape)

...

@@ -301,19 +302,19 @@ print(data.shape)

...

@@ -301,19 +302,19 @@ print(data.shape)

~~~

~~~

{: .output}

{: .output}

This tells us that `data`has 60 rows and 40 columns. When we created the

The output tells us that the `data` array variable contains 60 rows and 40 columns. When we created the

variable `data` to store our arthritis data, we didn't just create the array, we also

variable `data` to store our arthritis data, we didn't just create the array; we also

created information about the array, called [members]({{ page.root }}/reference/#member) or

created information about the array, called [members]({{ page.root }}/reference/#member) or

attributes. This extra information describes `data` in

attributes. This extra information describes `data` in

the same way an adjective describes a noun.

the same way an adjective describes a noun.

`data.shape` is an attribute of `data` which describes the dimensions of `data`.

`data.shape` is an attribute of `data` which describes the dimensions of `data`.

We use the same dotted notation for the attributes of variables

We use the same dotted notation for the attributes of variables

that we use for the functions in libraries

that we use for the functions in libraries

because they have the same part-and-whole relationship.

because they have the same part-and-whole relationship.

If we want to get a single number from the array,

If we want to get a single number from the array,

we must provide an [index]({{ page.root }}/reference/#index) in square brackets,

we must provide an [index]({{ page.root }}/reference/#index) in square brackets after the variable name,

just as we do in math when referring to an element of a matrix. Our inflammation data has two dimensions, so we will need to use two indices to refer to a value:

just as we do in math when referring to an element of a matrix. Our inflammation data has two dimensions, so we will need to use two indices to refer to one specific value:

~~~

~~~

print('first value in data:', data[0, 0])

print('first value in data:', data[0, 0])

...

@@ -337,7 +338,7 @@ middle value in data: 13.0

...

@@ -337,7 +338,7 @@ middle value in data: 13.0

The expression `data[30, 20]` accesses the element at row 30, column 20. While this expression may not surprise you,

The expression `data[30, 20]` accesses the element at row 30, column 20. While this expression may not surprise you,

`data[0, 0]` might.

`data[0, 0]` might.

Programming languages like Fortran, MATLAB and R start counting at 1,

Programming languages like Fortran, MATLAB and R start counting at 1

because that's what human beings have done for thousands of years.

because that's what human beings have done for thousands of years.

Languages in the C family (including C++, Java, Perl, and Python) count from 0

Languages in the C family (including C++, Java, Perl, and Python) count from 0

because it represents an offset from the first value in the array (the second

because it represents an offset from the first value in the array (the second

...

@@ -360,7 +361,7 @@ the index is how many steps we have to take from the start to get the item we wa

...

@@ -360,7 +361,7 @@ the index is how many steps we have to take from the start to get the item we wa

> What may also surprise you is that when Python displays an array,

> What may also surprise you is that when Python displays an array,

> it shows the element with index `[0, 0]` in the upper left corner

> it shows the element with index `[0, 0]` in the upper left corner

> rather than the lower left.

> rather than the lower left.

> This is consistent with the way mathematicians draw matrices,

> This is consistent with the way mathematicians draw matrices

> but different from the Cartesian coordinates.

> but different from the Cartesian coordinates.

> The indices are (row, column) instead of (column, row) for the same reason,

> The indices are (row, column) instead of (column, row) for the same reason,

> which can be confusing when plotting data.

> which can be confusing when plotting data.

...

@@ -422,6 +423,7 @@ print('small is:')

...

@@ -422,6 +423,7 @@ print('small is:')

print(small)

print(small)

~~~

~~~

{: .language-python}

{: .language-python}

The above example selects rows 0 through 2 and columns 36 through to the end of the array.

~~~

~~~

small is:

small is:

...

@@ -433,9 +435,9 @@ small is:

...

@@ -433,9 +435,9 @@ small is:

Arrays also know how to perform common mathematical operations on their values.

Arrays also know how to perform common mathematical operations on their values.

The simplest operations with data are arithmetic:

The simplest operations with data are arithmetic:

add, subtract, multiply, and divide.

addition, subtraction, multiplication, and division.

When you do such operations on arrays,

When you do such operations on arrays,

the operation is done on each individual element of the array.

the operation is done element-by-element.

Thus:

Thus:

~~~

~~~

...

@@ -444,7 +446,7 @@ doubledata = data * 2.0

...

@@ -444,7 +446,7 @@ doubledata = data * 2.0

{: .language-python}

{: .language-python}

will create a new array `doubledata`

will create a new array `doubledata`

whose elements have the value of two times the value of the corresponding elements in `data`:

each elements of which is twice the value of the corresponding element in `data`:

~~~

~~~

print('original:')

print('original:')

...

@@ -467,7 +469,7 @@ doubledata:

...

@@ -467,7 +469,7 @@ doubledata:

{: .output}

{: .output}

If,

If,

instead of taking an array and doing arithmetic with a single value (as above)

instead of taking an array and doing arithmetic with a single value (as above),

you did the arithmetic operation with another array of the same shape,

you did the arithmetic operation with another array of the same shape,

the operation will be done on corresponding elements of the two arrays.

the operation will be done on corresponding elements of the two arrays.

Thus:

Thus:

...

@@ -494,8 +496,8 @@ tripledata:

...

@@ -494,8 +496,8 @@ tripledata:

~~~

~~~

{: .output}

{: .output}

Often, we want to do more than add, subtract, multiply, and divide values of data.

Often, we want to do more than add, subtract, multiply, and divide array elements.

NumPy knows how to do more complex operations on arrays.

NumPy knows how to do more complex operations, too.

If we want to find the average inflammation for all patients on all days,

If we want to find the average inflammation for all patients on all days,

for example,

for example,

we can ask NumPy to compute `data`'s mean value:

we can ask NumPy to compute `data`'s mean value:

...

@@ -512,8 +514,6 @@ print(numpy.mean(data))

...

@@ -512,8 +514,6 @@ print(numpy.mean(data))

`mean` is a [function]({{ page.root }}/reference/#function) that takes

`mean` is a [function]({{ page.root }}/reference/#function) that takes

an array as an [argument]({{ page.root }}/reference/#argument).

an array as an [argument]({{ page.root }}/reference/#argument).