0% found this document useful (0 votes)
10 views

Numpy Examples

Uploaded by

pranavialagara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Numpy Examples

Uploaded by

pranavialagara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import numpy as np

first_array=np.array([1,3,5,7])
second_array=np.array([2,4,6,8])
result1=first_array+second_array
print("using the + operator:",result1)
result2=np.add(first_array,second_array)
print("using the add() function:",result2)

first_array=np.array([3,9,27,81])
second_array=np.array([2,4,8,16])
result1=first_array-second_array
print("using the - operator:",result1)
result2=np.subtract(first_array,second_array)
print("using the subtract() function:",result2)

first_array=np.array([1,3,5,7])
second_array=np.array([2,4,6,8])
result1=first_array*second_array
print("using the * operator:",result1)
result2=np.multiply(first_array,second_array)
print("using the multiply() function:",result2)

first_array=np.array([1,2,3])
second_array=np.array([4,5,6])
result1=first_array/second_array
print("using the / operator:",result1)
result2=np.divide(first_array,second_array)
print("using the divide() function:",result2)

array1=np.array([1,2,3])
result1=array1**2
print("using the ** operator:",result1)
result2=np.power(array1,2)
print("using the power() function:",result2)

first_array=np.array([9,10,20])
second_array=np.array([2,5,7])
result1=first_array%second_array
print("using the % operator:",result1)
result2=np.mod(first_array,second_array)
print("using the mod() function:",result2)

import numpy as np
array1=np.array([1,3,5])
print("np.array():\n",array1)
array2=np.zeros((3,3))
print("n\nnp.zeros():\n",array2)
array3=np.ones((2,4))
print("\nnp.ones():\n",array3)
array1=np.array([1,3,5,7,9,11])
array2=np.reshape(array1,(2,3))

array3=np.transpose(array2)
print("original array:\n",array1)
print("\nreshaped array:\n",array2)
print("\ntransposed array:\n",array3)

marks=np.array([76,78,81,66,85])
mean_marks=np.mean(marks)
print("mean:",mean_marks)
median_marks=np.median(marks)
print("median:",median_marks)
min_marks=np.min(marks)
print("minimum marks:",min_marks)
max_marks=np.max(marks)
print("maximum marks:",max_marks)

You might also like