forked from sarthak77/numpy-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_creation.py
49 lines (36 loc) · 1.1 KB
/
array_creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
a=np.array([2,3,4])
print(a)
b=np.arange(1,11,1).reshape(5,2)
print(b)
c=np.array([(1.5,2,3), (4,5,6),(1,2,3)])#2d array
print(c)
d=np.array([[(1.5,2,3), (4,5,6)],[(1,2,3),(5,6,7)]])#3d array
print(d)
e = np.array( [ [1,2], [3,4] ], dtype=complex )
print(e)
#####################################################################
"""
Often, the elements of an array are originally unknown, but its size
is known. Hence, NumPy offers several functions to create arrays with
initial placeholder content. These minimize the necessity of growing
arrays, an expensive operation.
The function zeros creates an array full of zeros, the function ones
creates an array full of ones, and the function empty creates an array
whose initial content is random and depends on the state of the memory.
By default, the dtype of the created array is float64.
"""
a=np.zeros((10,10))
print(a)
a=np.ones((10,10))
print(a)
a=np.empty((11,11))
print(a)
a=np.linspace(1,10,10)#from 1 to 10, 10 numbers
print(a)
a=np.random.random(10).reshape(5,2)
print(a)
def f(x,y):
return (10*x+y)
a=np.fromfunction(f,(5,4))
print(a)