In: Computer Science
Challenge 1: Python is one of the world’s most widely-used analytics platforms. It is more popular than R generally, it runs faster than R, and its analytic capabilities are rapidly improving. You'll want to use Anaconda Python because it includes many packages of use for analytics. Download Python 3.x at https://www.anaconda.com/distribution/ and install it.
Challenge 2: Spyder is an open-source, integrated development environment for data scientists to program in Python. You already installed it when you installed Anaconda's Python. On your computer, find and open Anaconda-Navigator and launch Spyder.
Note: If Spyder asks if you want to upgrade it, answer no. Otherwise you may be upgrading to a version that is not compatible with your version of Anaconda's Python.
Note: PyCharm is very popular and, by some accounts, a better IDE than Spyder. You are welcome to use PyCharm instead of Spyder.
Challenge 3: In Spyder, create a new script, add a multi-line comment at the top with the name of the workshop, your name, the date, and any other useful information. You should always have such a comment at the top. Save the script to your folder.
Copy and paste the remaining challenges in this same script. Note: When you paste into Spyder, everything may end up on one line. If you copy from here, paste into Word, copy from Word and paste into Spyder, you should get multiple lines.
NOTES:
'''Challenge 4: Assign "Hello World" to a variable and print it to
the console.
Use Spyder's "Run selection or current line" feature to execute
your program.
Python Basics Cheat Sheet: https://www.dataquest.io/blog/python-cheat-sheet
'''
'''Challenge 5: Create a list with the names of three of your
friends
and print it.
'''
'''Challenge 6: Python relies on packages for a wide range of
functionality.
Three of the most important are numpy, scipy and pandas.
- numpy has numerical processing functionality;
- Tutorial: https://docs.scipy.org/doc/numpy/user/quickstart.html
- scipy has scientific processing functionality, including
optimization
and statistical analysis
- Docs: https://docs.scipy.org/doc/scipy-1.2.1/reference/
- pandas (Python Data Analysis Library) has extensive functionality
for
data manipulation. It includes tabular DataFrames. It is very
fast
and often used instead of databases for data manipulation.
- 10-min Intro: http://pandas.pydata.org/pandas-docs/stable/getting_started/10min.htmls
These packages are already installed with Anaconda's Python.
Import numpy as np at the of your script, just below your
introductory
comments.
'''
'''Challenge 7: Create these numpy arrays: (1, 3, 5), (2, 4,
6).
Add them together. Print the results.
Numpy Cheat Sheet: https://www.dataquest.io/blog/numpy-cheat-sheet
'''
'''Challenge 8: Multiply the vectors together. Print the
results.'''
'''Challenge 9: Create a test to see if each element of the
vector
(1, 3, 5) > 2. Print the results.
'''
'''Challenge 10: Print the second element of the vector (1, 3,
5).
Note: Python starts counting a 0.
'''
'''Challenge 11: Replace the second element of the vector with
-3.
Print the results.
'''
'''Challenge 12: Print the second and third elements of the
vector.'''
'''Challenge 13: Replicate the vector and print the new
vector.
'''
'''Challenge 14: Create a list with numbers from 1-10.'''
SOURCE CODE:
"""
NAME OF THE WORKSHOP:
NAME:
Created on Sat Sep 28 14:30:50 2019
"""
#importing numpy package as np (challenge 6)
import numpy as np
#assign "Hello world" string to varible string (challenge 4)
string="Hello World"
print(string)
#reading three freinds name (challenge 5)
friend1=input("Enter 1st friend name:")
friend2=input("Enter 2nd friend name:")
friend3=input("Enter 3rd friend name:")
li=[friend1,friend2,friend3]
print(li)
#creating numpy arrays (challenge 7)
arr1=(1,3,5)
arr2=(2,4,6)
vector1=np.array(arr1)
vector2=np.array(arr2)
#addition of arrays
arr_add=np.add(vector1,vector2)
print("Addition of arrays:",arr_add)
#multiplication of arrays (challenge 8)
arr_mul=np.multiply(vector1,vector2)
print("Multiplication of arrays:",arr_mul)
# test to see each element of the vector >2 or not (challenge
9)
print("\nVector values greater than 2 are:")
for i in vector1:
if(i>2):
print(i," is greater
than 2")
else:
print(i," is less than
or equal to 2")
#print second elemnt of vector1 (challenge 10)
print("\nSecond element of vector:",vector1[1])
#since second element have index 1 (index starts from 0)
#challenge 11
vector1[1]=-3
print("\nAfter modification of second element:",vector1)
#challengee 12
print("\nSecond and Third elements are :",vector1[1:3]) #printing
2nd and 3rd elements index 1-3
#challenge 13
vector3=np.copy(vector1)
print("\nreplicated vector :",vector3)
#challenge 14
lis=[i for i in range(1,11)]
print("\nlist with numbers 1-10 :",lis)
CODE SCREENSHOT:
OUTPUT: