Skip to content

Commit 0fa7c06

Browse files
Add files via upload
1 parent b32b20b commit 0fa7c06

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

numpy.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import numpy as np
2+
3+
4+
'''
5+
#Q1.Create a numpy array with 10 elements of the shape(10,1) using np.random and find out the mean of the elements using basic numpy functions.
6+
7+
8+
array=np.random.rand(10,1)
9+
print("Array:\n",array)
10+
print("Mean: ",array.mean(axis=0))
11+
12+
'''
13+
14+
15+
16+
'''
17+
#Q2.Create a numpy array with 20 elements of the shape(20,1) using np.random find the variance and standard deviation of the elements.
18+
19+
array=np.random.rand(20,1)
20+
print("Array:\n",array)
21+
22+
print("Mean: ",array.mean(axis=0))
23+
print("Variance: ",array.var(axis=0))
24+
print("Standar Deviation: ",array.std(axis=0))
25+
26+
'''
27+
28+
29+
30+
31+
'''
32+
#Q3.Create a numpy array A of shape(10,20) and B of shape (20,25) using np.random. Print the matrix which is the matrix multiplication of A and B. The shape of the new matrix should be (10,25). Using basic numpy math functions only find the sum of all the elements of the new matrix.
33+
34+
x=np.random.rand(10,20)
35+
y=np.random.rand(20,25)
36+
37+
z=x.dot(y)
38+
print(z)
39+
print("Shape of new array: ",np.shape(z))
40+
print("Sum of elements in new array: ",np.sum(z))
41+
'''
42+
43+
44+
45+
'''
46+
#Q4.Create a numpy array A of shape(10,1).Using the basic operations of the numpy array generate an array of shape(10,1) such that each element is the following function applied on each element of A.
47+
#f(x)=1 / (1 + exp(-x))
48+
#Apply this function to each element of A and print the new array holding the value the function returns
49+
#Example:
50+
#a=[a1,a2,a3]
51+
#n(new array to be printed )=[ f(a1), f(a2), f(a3)]
52+
53+
54+
55+
A=np.random.rand(10,1)
56+
print("\nArray A:\n",A)
57+
58+
f=lambda x:(1/(1+np.exp(-x)))
59+
60+
print("\nNew array:\n",np.array(list(map(f,A))))
61+
62+
'''

0 commit comments

Comments
 (0)