forked from PacktPublishing/Machine-Learning-and-Data-Science-with-Python-A-Complete-Beginners-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_tutorials_numpy.py
More file actions
36 lines (23 loc) · 737 Bytes
/
Copy pathquick_tutorials_numpy.py
File metadata and controls
36 lines (23 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 05:18:39 2019
@author: abhilash
"""
import numpy
mylist = [[1, 2, 3], [3, 4, 5]]
#convert the python list into numpy array
myarray = numpy.array(mylist)
print(myarray)
print(myarray.shape)
#get the contents of the numpy array
print("First Row: %s" % myarray[0])
print("Last Row: %s" % myarray[-1])
#get a specific value
print("specific row and col: %s" % myarray[0, 2])
#get the whole column
print("whole col: %s" % myarray[:, 2])
#arithmetic operations with numpy array
myarray1 = numpy.array([2, 2, 2])
myarray2 = numpy.array([3, 3, 3])
print("Addition: %s" % (myarray1 + myarray2))
print("Multiplication: %s" % (myarray1 * myarray2))