N-004_10_basic_attribute_in_array.py
0.00MB
no. | Attribute | Description | example code |
1 | ndim | The number of dimensions of the array. |
import numpy as np arr = np.array( [ [1, 2, 3], [4, 5, 6] ] ) print(arr.ndim) # Output: 2 |
2 | shape | The shape of the array (dimensions). |
print(arr.shape) # Output: (2, 3) |
3 | size | The total number of elements in the array. |
print(arr.size) # Output: 6 |
4 | dtype | The data type of the array’s elements. | print(arr.dtype) # Output: int64 |
5 | itemsize | The size (in bytes) of each element in the array. |
print(arr.itemsize) # Output: 8 |
6 | nbytes | The total number of bytes consumed by the elements of the array. |
print(arr.nbytes) # Output: 48 |
7 | T | The transposed array. | print(arr.T) # Output: array([[1, 4], [2, 5], [3, 6]]) print( transpose(arr) ) # same |
8 | flat | A flat iterator over the array. | for item in arr.flat: print(item) # Output: 1 2 3 4 5 6 |
9 | real | The real part of the array elements (useful for complex numbers). |
arr_complex = np.array([1+2j, 3+4j]) print(arr_complex.real) # Output: [1. 3.] |
10 | imag | The imaginary part of the array elements (useful for complex numbers) |
print(arr_complex.imag) # Output: [2. 4.] |
'Python' 카테고리의 다른 글
Python_EX-002. Average Score Comparison (NumPy Practice) (0) | 2025.01.20 |
---|---|
Python_N-005. 10 basic attributes in array (2) (0) | 2025.01.19 |
Python_N-003. Data Type in array (0) | 2025.01.19 |
Python_N-002. random module (0) | 2025.01.18 |
Python_N-001. basic commend in Numpy (0) | 2025.01.18 |