Skip to content

Instantly share code, notes, and snippets.

@Ravisiswaliya
Created January 7, 2018 09:31
Show Gist options
  • Save Ravisiswaliya/54c7ebaff81b5b15fd5e49ca18c63943 to your computer and use it in GitHub Desktop.
Save Ravisiswaliya/54c7ebaff81b5b15fd5e49ca18c63943 to your computer and use it in GitHub Desktop.
import numpy as np
import time
import sys
'''
#here I'm comparing memory occupied by both
#menory occupied by list
s = range(1000)
print('memory occupied by List',sys.getsizeof(5)*len(s))
#menory occupied by numpy
d = np.arange(1000)
print('memory occupied by Numpy Array',d.size*d.itemsize)
'''
'''
#here i am comparing speed of list and numpy array
size = 10000000
#checking list taken time
l1 = range(size)
l2 = range(size)
start = time.time()
result = [(x,y) for x,y in zip(l1,l2)]
print('Time taken by List:', time.time()-start)
#checking numpy array taken time
a1 = np.arange(size)
a2 = np.arange(size)
start2 = time.time()
result_numpy = a1+a2
print('Time taken by numpy:', time.time()-start2)
'''
#2-D array
a = np.array([(1,2,3,4),(5,6,7,8)])
b = np.array([(1,2,3,4),(5,6,7,8)])
#to know type of array
#print(a.ndim)
#to check the size of an array
#print(a.size)
#reshape the numpy array
#print(a.reshape(4,2)) # i change into 4rows,2 column
#getting the sum of array
#print(a.sum())
#getting sum of axis
#print(a.sum(axis=0)) #here I am addning
#finding squt of array element
#print(np.sqrt(a))
#standrad division
#print(np.std(a))
#adding to array
#print(a+b) #we can also do -,*,/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment