<a href="https://colab.research.google.com/github/annissatessffaaye/QAPython/blob/master/02_Python_Numpy.ipynb" target="_parent"></a>


```python

```

The first thing we want to do is import numpy.


```python
import numpy as np
```

Let us first define a Python list containing the ages of 6 people.


```python
ages_list = [10, 5, 8, 32, 65, 43]
print(ages_list)
```

    [10, 5, 8, 32, 65, 43]


There are 3 main ways to instantiate a Numpy ndarray object. One of these is to use `np.array(<collection>)`


```python
ages = np.array(ages_list)
print(type(ages))
print(ages)
```

    <class 'numpy.ndarray'>
    [10  5  8 32 65 43]



```python
print(ages)
print("Size:\t" , ages.size)
print("Shape:\t", ages.shape)
```

    [10  5  8 32 65 43]
    Size:	 6
    Shape:	 (6,)



```python
zeroArr = np.zeros(5)
print(zeroArr)
```

    [0. 0. 0. 0. 0.]


### Multi-dim

Now let us define a new list containing the weights of these 6 people.


```python
weight_list = [32, 18, 26, 60, 55, 65]
```

Now, we define an ndarray containing all fo this information, and again print the size and shape of the array.


```python
people = np.array([ages_list, weight_list])

print("People:\t" , people)
print("Size:\t" , people.size)
print("Shape:\t", people.shape)
```

    People:	 [[10  5  8 32 65 43]
     [32 18 26 60 55 65]]
    Size:	 12
    Shape:	 (2, 6)



```python
people = people.reshape(12,1)
print("People:\t" , people)
print("Size:\t" , people.size)
print("Shape:\t", people.shape)
```

    People:	 [[10]
     [ 5]
     [ 8]
     [32]
     [65]
     [43]
     [32]
     [18]
     [26]
     [60]
     [55]
     [65]]
    Size:	 12
    Shape:	 (12, 1)


###### Note: The new shape must be the same "size" as the old shape

### Exercise

* Generate a 1D numpy array with the values [7, 9, 65, 33, 85, 99]

* Generate a matrix (2D numpy array) of the values:

\begin{align}
  \mathbf{A} =
  \begin{pmatrix}
    1 & 2 & 4 \\
    2 & 3 & 0 \\
    0 & 5 & 1
  \end{pmatrix}
\end{align}

* Change the dimensions of this array to another permitted shape

## Array Generation

Instead of defining an array manually, we can ask numpy to do it for us.

The `np.arange()` method creates a range of numbers with user defined steps between each.


```python
five_times_table = np.arange(0, 55, 5)
five_times_table
```




    array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50])



The `np.linspace()` method will produce a range of evenly spaced values, starting, ending, and taking as many steps as you specify.


```python
five_spaced = np.linspace(0,50,11)
print(five_spaced)
```

    [ 0.  5. 10. 15. 20. 25. 30. 35. 40. 45. 50.]


The `.repeat()` method will repeat an object you pas a specified number of times.


```python
twoArr = np.repeat(2, 10)
print(twoArr)
```

    [2 2 2 2 2 2 2 2 2 2]


The `np.eye()` functions will create an identity matrix/array for us.


```python
identity_matrix = np.eye(6)
print(identity_matrix)
```

    [[1. 0. 0. 0. 0. 0.]
     [0. 1. 0. 0. 0. 0.]
     [0. 0. 1. 0. 0. 0.]
     [0. 0. 0. 1. 0. 0.]
     [0. 0. 0. 0. 1. 0.]
     [0. 0. 0. 0. 0. 1.]]


# Operations

There are many, many operations which we can perform on arrays. Below, we demonstrate a few.

What is happening in each line?


```python
five_times_table
```




    array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50])




```python
print("1:", 2 * five_times_table)
print("2:", 10 + five_times_table)
print("3:", five_times_table - 1)
print("4:", five_times_table/5)
print("5:", five_times_table **2)
print("6:", five_times_table < 20)
```

    1: [  0  10  20  30  40  50  60  70  80  90 100]
    2: [10 15 20 25 30 35 40 45 50 55 60]
    3: [-1  4  9 14 19 24 29 34 39 44 49]
    4: [ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
    5: [   0   25  100  225  400  625  900 1225 1600 2025 2500]
    6: [ True  True  True  True False False False False False False False]


### Speed Test

If we compare the speed at which we can do these operations compared to core python, we will notice a substantial difference.


```python
fives_list = list(range(0,5001,5))
fives_list
```




    [0,
     5,
     10,
     15,
     20,
     25,
     30,
     35,
     40,
     45,
     50,
     55,
     60,
     65,
     70,
     75,
     80,
     85,
     90,
     95,
     100,
     105,
     110,
     115,
     120,
     125,
     130,
     135,
     140,
     145,
     150,
     155,
     160,
     165,
     170,
     175,
     180,
     185,
     190,
     195,
     200,
     205,
     210,
     215,
     220,
     225,
     230,
     235,
     240,
     245,
     250,
     255,
     260,
     265,
     270,
     275,
     280,
     285,
     290,
     295,
     300,
     305,
     310,
     315,
     320,
     325,
     330,
     335,
     340,
     345,
     350,
     355,
     360,
     365,
     370,
     375,
     380,
     385,
     390,
     395,
     400,
     405,
     410,
     415,
     420,
     425,
     430,
     435,
     440,
     445,
     450,
     455,
     460,
     465,
     470,
     475,
     480,
     485,
     490,
     495,
     500,
     505,
     510,
     515,
     520,
     525,
     530,
     535,
     540,
     545,
     550,
     555,
     560,
     565,
     570,
     575,
     580,
     585,
     590,
     595,
     600,
     605,
     610,
     615,
     620,
     625,
     630,
     635,
     640,
     645,
     650,
     655,
     660,
     665,
     670,
     675,
     680,
     685,
     690,
     695,
     700,
     705,
     710,
     715,
     720,
     725,
     730,
     735,
     740,
     745,
     750,
     755,
     760,
     765,
     770,
     775,
     780,
     785,
     790,
     795,
     800,
     805,
     810,
     815,
     820,
     825,
     830,
     835,
     840,
     845,
     850,
     855,
     860,
     865,
     870,
     875,
     880,
     885,
     890,
     895,
     900,
     905,
     910,
     915,
     920,
     925,
     930,
     935,
     940,
     945,
     950,
     955,
     960,
     965,
     970,
     975,
     980,
     985,
     990,
     995,
     1000,
     1005,
     1010,
     1015,
     1020,
     1025,
     1030,
     1035,
     1040,
     1045,
     1050,
     1055,
     1060,
     1065,
     1070,
     1075,
     1080,
     1085,
     1090,
     1095,
     1100,
     1105,
     1110,
     1115,
     1120,
     1125,
     1130,
     1135,
     1140,
     1145,
     1150,
     1155,
     1160,
     1165,
     1170,
     1175,
     1180,
     1185,
     1190,
     1195,
     1200,
     1205,
     1210,
     1215,
     1220,
     1225,
     1230,
     1235,
     1240,
     1245,
     1250,
     1255,
     1260,
     1265,
     1270,
     1275,
     1280,
     1285,
     1290,
     1295,
     1300,
     1305,
     1310,
     1315,
     1320,
     1325,
     1330,
     1335,
     1340,
     1345,
     1350,
     1355,
     1360,
     1365,
     1370,
     1375,
     1380,
     1385,
     1390,
     1395,
     1400,
     1405,
     1410,
     1415,
     1420,
     1425,
     1430,
     1435,
     1440,
     1445,
     1450,
     1455,
     1460,
     1465,
     1470,
     1475,
     1480,
     1485,
     1490,
     1495,
     1500,
     1505,
     1510,
     1515,
     1520,
     1525,
     1530,
     1535,
     1540,
     1545,
     1550,
     1555,
     1560,
     1565,
     1570,
     1575,
     1580,
     1585,
     1590,
     1595,
     1600,
     1605,
     1610,
     1615,
     1620,
     1625,
     1630,
     1635,
     1640,
     1645,
     1650,
     1655,
     1660,
     1665,
     1670,
     1675,
     1680,
     1685,
     1690,
     1695,
     1700,
     1705,
     1710,
     1715,
     1720,
     1725,
     1730,
     1735,
     1740,
     1745,
     1750,
     1755,
     1760,
     1765,
     1770,
     1775,
     1780,
     1785,
     1790,
     1795,
     1800,
     1805,
     1810,
     1815,
     1820,
     1825,
     1830,
     1835,
     1840,
     1845,
     1850,
     1855,
     1860,
     1865,
     1870,
     1875,
     1880,
     1885,
     1890,
     1895,
     1900,
     1905,
     1910,
     1915,
     1920,
     1925,
     1930,
     1935,
     1940,
     1945,
     1950,
     1955,
     1960,
     1965,
     1970,
     1975,
     1980,
     1985,
     1990,
     1995,
     2000,
     2005,
     2010,
     2015,
     2020,
     2025,
     2030,
     2035,
     2040,
     2045,
     2050,
     2055,
     2060,
     2065,
     2070,
     2075,
     2080,
     2085,
     2090,
     2095,
     2100,
     2105,
     2110,
     2115,
     2120,
     2125,
     2130,
     2135,
     2140,
     2145,
     2150,
     2155,
     2160,
     2165,
     2170,
     2175,
     2180,
     2185,
     2190,
     2195,
     2200,
     2205,
     2210,
     2215,
     2220,
     2225,
     2230,
     2235,
     2240,
     2245,
     2250,
     2255,
     2260,
     2265,
     2270,
     2275,
     2280,
     2285,
     2290,
     2295,
     2300,
     2305,
     2310,
     2315,
     2320,
     2325,
     2330,
     2335,
     2340,
     2345,
     2350,
     2355,
     2360,
     2365,
     2370,
     2375,
     2380,
     2385,
     2390,
     2395,
     2400,
     2405,
     2410,
     2415,
     2420,
     2425,
     2430,
     2435,
     2440,
     2445,
     2450,
     2455,
     2460,
     2465,
     2470,
     2475,
     2480,
     2485,
     2490,
     2495,
     2500,
     2505,
     2510,
     2515,
     2520,
     2525,
     2530,
     2535,
     2540,
     2545,
     2550,
     2555,
     2560,
     2565,
     2570,
     2575,
     2580,
     2585,
     2590,
     2595,
     2600,
     2605,
     2610,
     2615,
     2620,
     2625,
     2630,
     2635,
     2640,
     2645,
     2650,
     2655,
     2660,
     2665,
     2670,
     2675,
     2680,
     2685,
     2690,
     2695,
     2700,
     2705,
     2710,
     2715,
     2720,
     2725,
     2730,
     2735,
     2740,
     2745,
     2750,
     2755,
     2760,
     2765,
     2770,
     2775,
     2780,
     2785,
     2790,
     2795,
     2800,
     2805,
     2810,
     2815,
     2820,
     2825,
     2830,
     2835,
     2840,
     2845,
     2850,
     2855,
     2860,
     2865,
     2870,
     2875,
     2880,
     2885,
     2890,
     2895,
     2900,
     2905,
     2910,
     2915,
     2920,
     2925,
     2930,
     2935,
     2940,
     2945,
     2950,
     2955,
     2960,
     2965,
     2970,
     2975,
     2980,
     2985,
     2990,
     2995,
     3000,
     3005,
     3010,
     3015,
     3020,
     3025,
     3030,
     3035,
     3040,
     3045,
     3050,
     3055,
     3060,
     3065,
     3070,
     3075,
     3080,
     3085,
     3090,
     3095,
     3100,
     3105,
     3110,
     3115,
     3120,
     3125,
     3130,
     3135,
     3140,
     3145,
     3150,
     3155,
     3160,
     3165,
     3170,
     3175,
     3180,
     3185,
     3190,
     3195,
     3200,
     3205,
     3210,
     3215,
     3220,
     3225,
     3230,
     3235,
     3240,
     3245,
     3250,
     3255,
     3260,
     3265,
     3270,
     3275,
     3280,
     3285,
     3290,
     3295,
     3300,
     3305,
     3310,
     3315,
     3320,
     3325,
     3330,
     3335,
     3340,
     3345,
     3350,
     3355,
     3360,
     3365,
     3370,
     3375,
     3380,
     3385,
     3390,
     3395,
     3400,
     3405,
     3410,
     3415,
     3420,
     3425,
     3430,
     3435,
     3440,
     3445,
     3450,
     3455,
     3460,
     3465,
     3470,
     3475,
     3480,
     3485,
     3490,
     3495,
     3500,
     3505,
     3510,
     3515,
     3520,
     3525,
     3530,
     3535,
     3540,
     3545,
     3550,
     3555,
     3560,
     3565,
     3570,
     3575,
     3580,
     3585,
     3590,
     3595,
     3600,
     3605,
     3610,
     3615,
     3620,
     3625,
     3630,
     3635,
     3640,
     3645,
     3650,
     3655,
     3660,
     3665,
     3670,
     3675,
     3680,
     3685,
     3690,
     3695,
     3700,
     3705,
     3710,
     3715,
     3720,
     3725,
     3730,
     3735,
     3740,
     3745,
     3750,
     3755,
     3760,
     3765,
     3770,
     3775,
     3780,
     3785,
     3790,
     3795,
     3800,
     3805,
     3810,
     3815,
     3820,
     3825,
     3830,
     3835,
     3840,
     3845,
     3850,
     3855,
     3860,
     3865,
     3870,
     3875,
     3880,
     3885,
     3890,
     3895,
     3900,
     3905,
     3910,
     3915,
     3920,
     3925,
     3930,
     3935,
     3940,
     3945,
     3950,
     3955,
     3960,
     3965,
     3970,
     3975,
     3980,
     3985,
     3990,
     3995,
     4000,
     4005,
     4010,
     4015,
     4020,
     4025,
     4030,
     4035,
     4040,
     4045,
     4050,
     4055,
     4060,
     4065,
     4070,
     4075,
     4080,
     4085,
     4090,
     4095,
     4100,
     4105,
     4110,
     4115,
     4120,
     4125,
     4130,
     4135,
     4140,
     4145,
     4150,
     4155,
     4160,
     4165,
     4170,
     4175,
     4180,
     4185,
     4190,
     4195,
     4200,
     4205,
     4210,
     4215,
     4220,
     4225,
     4230,
     4235,
     4240,
     4245,
     4250,
     4255,
     4260,
     4265,
     4270,
     4275,
     4280,
     4285,
     4290,
     4295,
     4300,
     4305,
     4310,
     4315,
     4320,
     4325,
     4330,
     4335,
     4340,
     4345,
     4350,
     4355,
     4360,
     4365,
     4370,
     4375,
     4380,
     4385,
     4390,
     4395,
     4400,
     4405,
     4410,
     4415,
     4420,
     4425,
     4430,
     4435,
     4440,
     4445,
     4450,
     4455,
     4460,
     4465,
     4470,
     4475,
     4480,
     4485,
     4490,
     4495,
     4500,
     4505,
     4510,
     4515,
     4520,
     4525,
     4530,
     4535,
     4540,
     4545,
     4550,
     4555,
     4560,
     4565,
     4570,
     4575,
     4580,
     4585,
     4590,
     4595,
     4600,
     4605,
     4610,
     4615,
     4620,
     4625,
     4630,
     4635,
     4640,
     4645,
     4650,
     4655,
     4660,
     4665,
     4670,
     4675,
     4680,
     4685,
     4690,
     4695,
     4700,
     4705,
     4710,
     4715,
     4720,
     4725,
     4730,
     4735,
     4740,
     4745,
     4750,
     4755,
     4760,
     4765,
     4770,
     4775,
     4780,
     4785,
     4790,
     4795,
     4800,
     4805,
     4810,
     4815,
     4820,
     4825,
     4830,
     4835,
     4840,
     4845,
     4850,
     4855,
     4860,
     4865,
     4870,
     4875,
     4880,
     4885,
     4890,
     4895,
     4900,
     4905,
     4910,
     4915,
     4920,
     4925,
     4930,
     4935,
     4940,
     4945,
     4950,
     4955,
     4960,
     4965,
     4970,
     4975,
     4980,
     4985,
     4990,
     4995,
     ...]




```python
five_times_table_lge = np.arange(0,5001,5)
five_times_table_lge
```




    array([   0,    5,   10, ..., 4990, 4995, 5000])




```python
%timeit five_times_table_lge + 5
```

    The slowest run took 26.25 times longer than the fastest. This could mean that an intermediate result is being cached.
    1000000 loops, best of 5: 1.66 µs per loop



```python
%timeit [e + 5 for e in fives_list]
```

    10000 loops, best of 5: 51 µs per loop


Boolean string operations can also be performed on ndarrays.


```python
words = np.array(["ten", "nine", "eight", "seven", "six"])

print(np.isin(words, 'e'))

print("e" in words)
["e" in word for word in words]
```

    [False False False False False]
    False





    [True, True, True, True, False]



# Transpose


```python
people.shape = (2, 6)
print(people, "\n")
print(people.T)
```

    [[10  5  8 32 65 43]
     [32 18 26 60 55 65]] 
    
    [[10 32]
     [ 5 18]
     [ 8 26]
     [32 60]
     [65 55]
     [43 65]]


# Data Types

As previously mentioned, ndarrays can only have one data type. If we want to obtain or change this, we use the `.dtype` attribute.


```python
people.dtype
```




    dtype('int64')



What is the data type of the below ndarray?


```python
ages_with_strings = np.array([10, 5, 8, '32', '65', '43'])
ages_with_strings
```




    array(['10', '5', '8', '32', '65', '43'], dtype='<U21')



What is the dtype of this array?


```python
ages_with_strings = np.array([10, 5, 8, '32', '65', '43'], dtype='int32')
ages_with_strings
```




    array([10,  5,  8, 32, 65, 43], dtype=int32)



What do you think has happened here?


```python
ages_with_strings = np.array([10, 5, 8, '32', '65', '43'])
print(ages_with_strings)
```

    ['10' '5' '8' '32' '65' '43']



```python
ages_with_strings.dtype = 'int32'
print(ages_with_strings)
```

    [49 48  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 53  0  0
      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 56  0  0  0  0  0
      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 51 50  0  0  0  0  0  0  0
      0  0  0  0  0  0  0  0  0  0  0  0 54 53  0  0  0  0  0  0  0  0  0  0
      0  0  0  0  0  0  0  0  0 52 51  0  0  0  0  0  0  0  0  0  0  0  0  0
      0  0  0  0  0  0]



```python
ages_with_strings.size
```




    126




```python
ages_with_strings.size/21
```




    6.0




```python
np.array([10, 5, 8, '32', '65', '43']).size
```




    6



The correct way to have changed the data type of the ndarray would have been to use the `.astype()` method, demonstrated below.


```python
ages_with_strings = np.array([10, 5, 8, '32', '65', '43'])
print(ages_with_strings)
print(ages_with_strings.astype('int32'))
```

    ['10' '5' '8' '32' '65' '43']
    [10  5  8 32 65 43]


### Exercise

* #### Create an array of string numbers, but use dtype to make it an array of floats.
* #### Transpose the matrix, printing the new size and shape.
* #### Use the .astype() method to convert the array to boolean.

## Array Slicing Operations

As before, we can use square brackets and indices to access individual values, and the colon operator to slice the array.


```python
five_times_table
```




    array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50])




```python
five_times_table[0]
```




    0




```python
five_times_table[-1]
```




    50




```python
five_times_table[:4]
```




    array([ 0,  5, 10, 15])




```python
five_times_table[4:]
```




    array([20, 25, 30, 35, 40, 45, 50])



We can also slice an n-dim ndarray., specifying the slice operation accross each axis.


```python
print(people)
people[:3, :3]
```

    [[10  5  8 32 65 43]
     [32 18 26 60 55 65]]





    array([[10,  5,  8],
           [32, 18, 26]])



### Exercise

* Create a numpy array with 50 zeros
* Create a np array of 2 repeated 20 times
* Create a numpy array from 0 to 2 $\pi$ in steps of 0.1

For one of the arrays generated:
* Get the first five values
* Get the last 3 values
* Get the 4th value to the 7th value

We can reverse an array by using `.flip()` or by using the `::` operator.


```python
reverse_five_times_table = np.flip(five_times_table)
reverse_five_times_table
```




    array([50, 45, 40, 35, 30, 25, 20, 15, 10,  5,  0])




```python
reverse_five_times_table = five_times_table[-1::-1]
print(reverse_five_times_table)
five_times_table
```

    [50 45 40 35 30 25 20 15 10  5  0]





    array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50])



We can also use the `::` operator to select steps of the original array.


```python
five_times_table[0::3] #Every 3rd element starting from 0
```




    array([ 0, 15, 30, 45])



### Exercise
Take one of the arrays you defined and
* #### Reverse it
* #### Only keep every 4th element.
* #### Get every 2nd element, starting from the last and moving backwards.

# Stats


```python
np.array([1.65432, 5.98765]).round(2)
```




    array([1.65, 5.99])




```python
nums = np.arange(0, 4, 0.2555)
```

### Exercise

* Compute min, max, sum, mean, median, variance, and standard deviation of the above array, all to to 2 decimal places.


```python
print("min = ", np.min(nums).round(2))
print("max = ", np.max(nums).round(2))
print("sum = ", np.sum(nums).round(2))
print("mean = ", np.mean(nums).round(2))
print("median = ", np.median(nums).round(2))
print("var = ", np.var(nums).round(2))
print("std = ", np.std(nums).round(2))
```

    min =  0.0
    max =  3.83
    sum =  30.66
    mean =  1.92
    median =  1.92
    var =  1.39
    std =  1.18


## Random

With `np.random`, we can generate a number of types of dataset, and create training data.

The below code simulates a fair coin toss.


```python
flip = np.random.choice([0,1], 10)
flip
```




    array([0, 0, 0, 1, 0, 1, 0, 1, 0, 0])




```python
np.random.rand(10,20,9)
```




    array([[[0.57903607, 0.70658326, 0.46823039, ..., 0.67872556,
             0.97668838, 0.59296004],
            [0.68265612, 0.35568777, 0.09006245, ..., 0.28822124,
             0.51443494, 0.52815057],
            [0.47576313, 0.19055337, 0.53289686, ..., 0.9720602 ,
             0.59957457, 0.00136381],
            ...,
            [0.96615173, 0.11924133, 0.27622075, ..., 0.60268858,
             0.76115508, 0.60700918],
            [0.7947058 , 0.60565686, 0.89898931, ..., 0.24012824,
             0.86142456, 0.26890588],
            [0.08503049, 0.85532359, 0.04862309, ..., 0.83191984,
             0.12922411, 0.05534613]],
    
           [[0.0571167 , 0.2627298 , 0.24012262, ..., 0.17173116,
             0.09829425, 0.78794406],
            [0.14690905, 0.71135404, 0.16426146, ..., 0.74632793,
             0.53593656, 0.4414745 ],
            [0.43014199, 0.74044911, 0.28382775, ..., 0.59250707,
             0.50027838, 0.29761281],
            ...,
            [0.24179913, 0.74530331, 0.74018769, ..., 0.14497582,
             0.26258718, 0.8021661 ],
            [0.72357274, 0.02393067, 0.03247564, ..., 0.55356794,
             0.41219468, 0.23650561],
            [0.49846368, 0.03640285, 0.50449892, ..., 0.38784041,
             0.1143238 , 0.09864435]],
    
           [[0.89092575, 0.67273482, 0.58401463, ..., 0.05977424,
             0.08851958, 0.38219284],
            [0.59141116, 0.36883351, 0.47516797, ..., 0.76518547,
             0.13250162, 0.46123038],
            [0.97293218, 0.82266408, 0.16817342, ..., 0.45949225,
             0.41081166, 0.56793835],
            ...,
            [0.16166455, 0.51404214, 0.21340341, ..., 0.07144955,
             0.96286045, 0.49441027],
            [0.01173436, 0.62760475, 0.44478   , ..., 0.51227539,
             0.1095556 , 0.77223662],
            [0.46022167, 0.96680813, 0.23408062, ..., 0.94361105,
             0.36161187, 0.22280426]],
    
           ...,
    
           [[0.7621445 , 0.71656463, 0.62140542, ..., 0.78161937,
             0.54050741, 0.35509936],
            [0.88235509, 0.57271812, 0.84588271, ..., 0.17100842,
             0.68256992, 0.49224554],
            [0.3103567 , 0.39843377, 0.32951047, ..., 0.38696677,
             0.74197158, 0.63489489],
            ...,
            [0.87627107, 0.58826   , 0.85497237, ..., 0.96820957,
             0.49715622, 0.44814367],
            [0.30571801, 0.03233591, 0.47085265, ..., 0.75714441,
             0.44313711, 0.08418118],
            [0.71783251, 0.90823314, 0.72704044, ..., 0.59965653,
             0.4231835 , 0.30740116]],
    
           [[0.76174456, 0.71447451, 0.77809227, ..., 0.48855986,
             0.9367547 , 0.38798618],
            [0.13485896, 0.07370139, 0.83190798, ..., 0.28765397,
             0.73623527, 0.97569682],
            [0.14505399, 0.84622162, 0.2885453 , ..., 0.7665278 ,
             0.54913027, 0.84625343],
            ...,
            [0.32134819, 0.56332715, 0.27872278, ..., 0.52081844,
             0.93898686, 0.39460526],
            [0.50629651, 0.36927313, 0.47709624, ..., 0.75562799,
             0.34733057, 0.44587717],
            [0.36130956, 0.07595216, 0.48705111, ..., 0.64247632,
             0.51827511, 0.40092295]],
    
           [[0.62058256, 0.54825669, 0.05118057, ..., 0.69456006,
             0.83958809, 0.9723071 ],
            [0.11303148, 0.6988732 , 0.27029805, ..., 0.57086763,
             0.76399898, 0.00617371],
            [0.57886927, 0.51730271, 0.77585789, ..., 0.2332254 ,
             0.16303748, 0.28319879],
            ...,
            [0.73697707, 0.48755375, 0.71565277, ..., 0.07981335,
             0.75923367, 0.93050114],
            [0.29318998, 0.50255749, 0.62045676, ..., 0.4489524 ,
             0.84108982, 0.50832608],
            [0.83918305, 0.65324551, 0.47826852, ..., 0.94658946,
             0.23852473, 0.08114226]]])



We can produce 1000 datapoints of a normally distributed data set by using `np.random.normal()`


```python
mu, sigma = 0, 0.1 # mean and standard deviation
s = np.random.normal(mu, sigma, 1000)
```

### Exercise
* Simulate a six-sided dice using numpy.random.choice(), generate a list of values you would obtain from 10 throws.
* Simulate a two-sided coin toss that is NOT fair: it is twice as likely to have head than tails.



```python

```

b1e595733a7c4e3832e0d7f5e20516ddba4bba09
ipynb
Jupyter Notebook
02_Python_Numpy.ipynb
annissatessffaaye/QA-Data-Engineering-Bootcamp-Azure-Python-SQL
9204dfb4b1e9ac4dd477200a2a79f9aed49c6a11
MIT
2021-11-23T19:57:34.000Z
2021-11-23T19:57:34.000Z
02_Python_Numpy.ipynb
annissatessffaaye/QA-Data-Engineering-Bootcamp-Azure-Python-SQL
9204dfb4b1e9ac4dd477200a2a79f9aed49c6a11
MIT
02_Python_Numpy.ipynb
annissatessffaaye/QA-Data-Engineering-Bootcamp-Azure-Python-SQL
9204dfb4b1e9ac4dd477200a2a79f9aed49c6a11
MIT
Qwen/Qwen-72B
1. YES
2. YES