Python
Python_N-001. basic commend in Numpy
X25WLK
2025. 1. 18. 14:32
A summary of the basic commands for using NumPy.
Operation | Command | Description |
Import NumPy | import numpy as np | Import the NumPy library |
Create Array | np.array( [1, 2, 3] ) | Create an array from a list |
Array of Zeros | np.zeros( 5 ) | Create an array of zeros |
Array of Ones | np.ones( 5 ) | Create an array of ones |
Identity Matrix | np.eye(3) | Create a 3x3 identity matrix |
Full Array |
np.full( (3, 3), fill_value ) | Create an array filled with a specific value |
Range Array | np.arange(10) np.range(10) |
Create an array with a range of values arange() : float range() : integer |
Linspace | np.linspace(0, 1, 10) | Select elements based on a condition |
Arithmetic Operation | array + 2 | Add 2 to each element of the array |
Element-wise Addition | array_1 + array_2 | Add two arrays element-wise |
Reshape Array | array.reshape((5, 1)) | Reshape an array |
Access Element | array[0] | Access the first element of the array |
Slice Array | array[1:4] | Access a slice of the array |
Sum | np.sum(array) | Calculate the sum of the array elements |
Mean | np.mean(array) | Calculate the mean of the array elements |
Max | np.max(array) | Find the maximum value in the array |
Min | np.min(array) | Find the minimum value in the array |
반응형