# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ![title](img/cover4.png)

# <center><em>Copyright! This material is protected, please do not copy or distribute.    by:<NAME></em></center>

# ***
# <h1 align="center">Udemy course : Python Bootcamp for Data Science 2021 Numpy Pandas & Seaborn</h1> 
#
# ***

# ### The Exercise for  Module 6
#
# #### Instruction:  Please write your code after the phrase " ## Your codes begin here:"

# #### Q1. In the next code cell, create a numpy array named 'array1'  that consists of random numbers with the shape (3,4), i.e. three rows and four columns? Then display it?
#
# **Hint**: To generate random numbers, you might need to use this function (**np.random.randn()**)
#
# The output shoulld look like this:
#
# output:
#
#   array    ([[-1.56035211, -0.0309776 , -0.62092842, -1.46458049],
#
#        [ 1.41194612, -0.47673214, -0.78046921,  1.07026774],
#        
#        [-1.2822926 , -1.3274789 ,  0.12633764,  0.86219372]])       

# +
import numpy as np
np.random.seed(50)   ## Used to generate the same numbers each time we run the script.

## Your codes begin here:


# -

# #### Q2. Display the shape and the dimension of 'array1', that was created in Q1?
#
# **Hint:** you need to use **print statements, print()** to display multiple lines of code. 
# The output should look like this:
#
# The output shoulld look like this:
#
# **output:** 
#
# The shape is:  (3, 4)
#
# The dimension is  2

# +
## Your codes begin here:



# -

# #### Q3. Display the data type of 'array1', that was created in Q1? 
#
# The output shoulld look like this:
#
# **output:**
#
# dtype('float64')

# +
## Your codes begin here:


# -

# #### Q4. Use your indexing skills to select only the last two columns and the last two rows from 'array1' that was created in Q1?
#
# **Hint: There is no universal answer to this question. 
#
#
# The output shoulld look like this:
#
# **output:**
#
# array([[ 1.44774523, -0.16963134],
#
#        [-0.94879155, -0.21160221]])

# +
## Your codes begin here:


# -

# #### Q5. Use boolean indexing to select only positive numbers from 'array1' that was created in Q1?
#
# The output shoulld look like this:
#
# **output:**
#
# array([1.41194612, 1.07026774, 0.12633764, 0.86219372])

# +
## Your codes begin here:


# -

# #### Q6. Transpose 'array1' that was created in Q1?
#
#
# The output shoulld look like this:
#
# **output:**
#
# array([[-1.56035211,  1.41194612, -1.2822926 ],
#
#        [-0.0309776 , -0.47673214, -1.3274789 ],
#        
#        [-0.62092842, -0.78046921,  0.12633764],
#        
#        [-1.46458049,  1.07026774,  0.86219372]])
#        

# +
## Your codes begin here:


# -

# #### Q7. Sort 'array1' within columns? Then display it?
# **Hint:** Sorting within columns means sorting along rows.
#
# The output shoulld look like this:
#
# **output:** 
#
# array([[-1.56035211, -1.3274789 , -0.78046921, -1.46458049],
#
#        [-1.2822926 , -0.47673214, -0.62092842,  0.86219372],
#        
#        [ 1.41194612, -0.0309776 ,  0.12633764,  1.07026774]])

# +
## Your codes begin here:


# -

# ***
# # Solutions
# ***

# #### Q1. In the next code cell, create a numpy array named 'array1'  that consists of random numbers with the shape (3,4), i.e. three rows and four columns? Then display it?      

# +
import numpy as np
np.random.seed(50)   ## Used to generate the same numbers each time we run the script.

## Your codes begin here:

array1 = np.random.randn(3,4)
array1
# -

# #### Q2. Display the shape and the dimension of 'array1', that was created in Q1?

# +
## Your codes begin here:

print('The shape is: ', array1.shape)
print('The dimension is ', array1.ndim)
# -

# #### Q3. Display the data type of 'array1', that was created in Q1? 

# +
## Your codes begin here:

array1.dtype
# -

# #### Q4. Use your indexing skills to select only the last two columns and the last two rows from 'array1' that was created in Q1?

# +
## Your codes begin here:

array1[1:,2:]
# -

# #### Q5. Use boolean indexing to select only positive numbers from 'array1' that was created in Q1?

# +
## Your codes begin here:

array1[array1 > 0]
# -

# #### Q6. Transpose 'array1' that was created in Q1?

# +
## Your codes begin here:

array1.T
# -

# #### Q7. Sort 'array1' within columns? Then display it?

# +
## Your codes begin here:

array1.sort(0)
array1
# -

# ***
#
# <h1 align="center">Thank You</h1> 
#
# ***

StarcoderdataJupyterScriptsDedupFiltered