Creating Arrays
a = np.array([1, 2, 3]) # 1D array b = np.array([(1.5, 2, 3), (4, 5, 6)], dtype=float) # 2D array with float type c = np.zeros((3, 4)) # Array of zeros d = np.ones((2, 3, 4),, dtype=np.int16) # Array of ones e = np.arange(10, 25, 5dtype=np.int16) # Array of evenly spaced values (step value) f = np.linspace(0, 2, 9) # Array of evenly spaced values (number of samples) g = np.full((2, 2), 7) # Constant array h = np.eye(2) # 2x2 identity matrix i = np.random.random((2, 2)) # Array with random values j = np.empty((3, 2)) # Empty array
|
|
|
Getting Info
np.info(np.ndarray.dtype) |
|
|
Comparison
a == b # Element-wise comparison a < 2 # Element-wise comparison np.array_equal(a, b) # Array-wise comparison |
|