Skip to content

Commit 04ff853

Browse files
authored
upload
basic numpy programs
0 parents  commit 04ff853

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

numpy/basicsNp.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Author CM
2+
# python3 basicNp.py
3+
# np functions slicing dicing
4+
import numpy as np
5+
a=np.array([1,2,3,4])
6+
b=np.array([5,6,7,8])
7+
print (a,b)
8+
for i in a:
9+
if i%2==0:
10+
print (i,end=" ")
11+
print (a+b)
12+
print (a.size) #finds lenght of array
13+
a=np.array([[1,2],[4,3]])
14+
print (a.shape) #dimentions of array
15+
print (a)
16+
print (np.ones((3,6)))
17+
x=np.array([1,2,3,4])
18+
print (x[-1]) #prints last element
19+
x=np.array([[1,2,3],[4,5,6],[6,7,8]])
20+
print (x)
21+
print (x[0:3,2]) #prints 0 to 3 rows but increase rows value by two
22+
print (x[:,1:3]) #prints colums from 1 to three
23+
for row in x:
24+
print (row)
25+
for cel in x.flat:
26+
print (cel)
27+
x=np.arange(1,7).reshape(2,3)
28+
y=np.arange(30).reshape(2,15)
29+
print(x)
30+
print (y)
31+
rs=np.hsplit(y,3) #splits horizontally
32+
print(rs[0])
33+
rs2=np.vsplit(y,2)
34+
print( rs2)
35+
print("")
36+
print((x))
37+
for x in np.nditer(x,order='F'): #order option are : 'F' 'C' 'A' 'K'
38+
print(x)

0 commit comments

Comments
 (0)