-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnestedarray.py
More file actions
75 lines (52 loc) · 1.73 KB
/
Copy pathnestedarray.py
File metadata and controls
75 lines (52 loc) · 1.73 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Dimensions in Arrays
#nested array: are arrays that have arrays as their elements.
#0-D Arrays
#0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array.
#1-D arrays An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array.
#2-D arrays An array that has 1-D arrays as its elements is called a 2-D array.These are often used to represent matrix or 2nd order tensors.
#3-D arrays An array that has 2-D arrays (matrices) as its elements is called 3-D array.These are often used to represent a 3rd order tensor.
import numpy as np
arr = np.array(42)#0 D array
arr1=np.array([1,2,3,4,5])#1 D array
arr2=np.array([[1,2,3,4,5],[6,7,8,9,10]])#2 D array
arr3 = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])#3D array
arr31=np.array([[[1,2,3],[1,2,3],[1,2,3]]]) #3D array
arr7=np.array([1,2,3,4,5], ndmin=7)
print(arr)
print(type(arr))
print(arr.ndim)
print(arr1)
print(type(arr1))
print(arr1.ndim)
print(arr2)
print(type(arr2))
print(arr2.ndim)
print(arr3)
print(type(arr3))
print(arr3.ndim)
print(arr31)
print(arr7)
print(arr7.ndim)
print(arr2.size)
print(arr2.shape)
print(arr2.dtype)
print(arr1[1])
#NumPy Arrays provides the ndim attribute that returns an integer that tells us how many dimensions the array have.
#Higher Dimensional Arrays
# An array can have any number of dimensions.
# When the array is created, you can define the number of dimensions by using the ndmin argument.
#arange and also we can reshape()
s=np.arange(12).reshape(3,4)
print(s)
print(s.min())
print(s.max())
print(s.sum())
print(s.mean())
print(s.std())
print(s.var())
print(s.axes=0)
print(s.cumsum=1)
print(s.axes(1))
#basic operation
#scaler and vector dot product .
#indexing #slicing