Np.ones trong python
The ones() function is used to get a new array of given shape and type, filled with ones. Syntax: Version: 1.15.0 Parameter: NameDescriptionRequired / Return value: [ndarray] Array of ones with the given shape, dtype, and order. Example-1: numpy.ones() Pictorial Presentation: Example-2: numpy.ones() where data type is float Python - NumPy Code Editor: Previous: identity() Follow us on Facebook and Twitter for latest update.
Numpy (Numeric Python): là một thư viện toán học phổ biến và mạnh mẽ của Python. Cho phép làm việc hiệu quả với ma trận và mảng, đặc biệt là dữ liệu ma trận và mảng lớn với tốc độ xử lý nhanh hơn nhiều lần khi chỉ sử dụng “core Python” đơn thuần. Hãy cùng tìm hiểu về thư viện này trong bài viết dưới đây: Cài đặt thư viện Numpy - Mở Command Prompt và gõ lệnh: Các thao tác với Numpy1. Khai báo thư viện
2. Khởi tạo mảnga) Khởi tạo mảng một chiều
OUTPUT: 0b) Khởi tạo mảng hai chiều
OUTPUT: 1 2c) Khởi tạo mảng ba chiều
OUTPUT: 3 4 5 6 7 8d) Khởi tạo với các hàm có sẵn
3. Thao tác với mảng
Output: 9 0 1 2Truy cập phần tử trong mảng Các phần tử trong mảng được đánh số từ 0 trở đi
Output 3 4 5 6 7 8Đọc mảng từ file .txt
Output Các hàm thống kê
Output: 9 0 1 2 3NumPy dtype Basic Type Available Numpy typesCommentsBoolean boolElements are 1 byte in size. Integer int8, int16, int32, int64, int128, intint defaults to the size of int in C for the platform. Unsigned Integer uint8, uint16, uint32, uint64, uint128, uint uint defaults to the size of unsigned int in c for the platform.Float float32, float64, float, longfloat Float is always a double precision floating point value (64 bits). longfloat represents large precision floats. Its size is platform dependent. Complex complex64, complex128, complex The real and complex elements of a complex64 are each represented by a single precision (32 bit) value for a total size of 64 bits. Strings str, unicode Unicode is always UTF32 (UCS4)Object objectRepresent items in array as Python objects.Records void Used for arbitrary data structures in record arrays.Toán tử trong NumPy Array Toán tửVí dụKết quả (+) Một số với mảng 3 + arr arr +3 (+) Mảng với mảng arr + a a + arr [3, 4, 7, 9, 11](-) Một số với mảng arr - 3 3 - arr [-2, 0, 1, 2, 3] [2, 0, -1, -2, -3] (-) Mảng với mảngarr - a a - arr [-1, 2, 1, 1, 1] [1, -2, -1, -1, -1] (*) Một số với mảng arr * 3 3 * arr [3, 9, 12, 15, 18](*) Mảng với mảng arr * a a * arr [2, 3, 12, 20, 30](/) Một số với mảng arr / 3 3 / arr [0.33333333, 1., 1.33333333, 1.66666667, 2.] [3., 1., 0.75, 0.6, 0.5] (/) Mảng với mảngarr / a a / arr [0.5, 3., 1.33333333, 1.25, 1.2] [2., 0.33333333, 0.75, 0.8, 0.83333333] Hạng của ma trậnnp.rank(arr) np.rank(arr1) 1 2 Lời kếtNhư vậy là mình đã giới thiệu cơ bản cho bạn về thư viện NumPy trong Python, nếu bạn muốn tìm hiểu thêm về thư viện NumPy thì bạn có thể vào ĐÂY để tham khảo thêm. Ở bài sau mình sẽ giới thiệu cho các bạn về cách xử lý dữ liệu với thư viện Pandas. |