Python - NumPy

Example 1
import numpy as np
x = np.array([5, 8, 
              9, 10, 
              11]) # using 'array' method

type(x)   # Displays type of array 'x'
Output
numpy.ndarray

Example 2
import numpy as np
y = np.array([[6, 9, 5], 
              [10, 82, 34]])  
print(y)
Output
array([[ 6,  9,  5],
       [10, 82, 34]])

Example 3
import numpy as np
y = np.array([[6, 9, 5], 
              [10, 82, 34]])  
print(y.ndim, y.shape, y.size, y.dtype, y.itemsize, y.nbytes)
Output
2 (2, 3) 6 int32 4 24

Example 4
import numpy as np
y = np.array([[6, 9, 5],
              [10, 82, 34]], 
             dtype='float64')  
print(y)
print(y.dtype)
Output
array([[  6.,   9.,   5.],
       [ 10.,  82.,  34.]])
float64

Example 5
import numpy as np
a = [[[4.1, 2.5], [1.1, 2.3], [9.1, 2.5]], 
     [[8.6, 9.9],[3.6, 4.3], [6.6, 0.3]]]

x = np.array(a, dtype='float64')

type(x), x.ndim, x.shape

Output
numpy.ndarray, 3, (2, 3, 2)

No comments:

Post a Comment