Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Ex.

1 Working with numpy arrays and Pandas data


frames
1a)Numpy arrays:

1. numpy.array():
import numpy as np
arr = np.array([4,5,6,2])
print("Array :",arr)
output:
Array : [4 5 6 2]

2. numpy.fromiter():
import numpy as np
iterable = (a*a for a in range(8))
arr = np.fromiter(iterable, float)
print("fromiter() array :",arr)
output:
fromiter() array : [ 0. 1. 4. 9. 16. 25. 36. 49. 64. 81. 100. 121.]

3. numpy.arange():
import numpy as np
m=np.arange(1, 20 , 2,dtype = np.float32)
print(m)
output:
[ 1. 3. 5. 7. 9. 11. 13. 15. 17. 19.]
4. numpy.linspace():
import numpy as np
m=np.linspace(3.5, 10, 3)
print(m)
output:
[ 3.5 6.75 10. ]

5. numpy.empty():
import numpy as np
n=np.empty([4, 3],dtype = np.int12,order = 'f')
print(n)
output:
[[ -1 -18512 0]
[ -1 32420 0]
[ -1 409 0]
[ -1 0 0]]

6. numpy.ones():
import numpy as np
v=np.ones([4, 3],dtype = np.int32,order = 'f')
print(v)
output:
[[1 1 1]
[1 1 1]
[1 1 1]
[1 1 1]]
7. numpy.zeros():
import numpy as np
c=np.zeros([4, 3], dtype = np.int32,order = 'f')
print(c)
output:
[[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]]

You might also like