Numpy learning path (1) -- array creation, numpy path
Array is the main object for Numpy operations and the main object for python data analysis. This series of articles is my note in Numpy learning.
The following
Numpy usage tips: array filtering instance code, numpy usage tips
This article focuses on the array filtering related to numpy usage techniques, as detailed below.
When Boolean array B is used as the subscript to access elements i
property value of 8 (Float64 occupies 64 bits, each byte length is 8, so 64/8, occupies 8 bytes), and the array item property of an element type of complex32 is 4 (32/8).
Ndarray.data: A buffer containing an actual array element, which is generally not required because it is typically fetched from an array's index.
Create an array
Let's start by creatin
article.
Ndarray.itemsize: The byte size of each element in the array. For example, an array with an element type of float64 Itemsiz has a value of 8 (float64 consumes 64 bits, each byte is 8, so 64/8, takes 8 bytes), and an array with an element type of complex32 has an item property of 4 (32/8).
Ndarray.data: A buffer that contains an actual
Python creates a two-dimensional list by storing a list in a list:L = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]NumPy can create a two-dimensional array directly:Import= Np.array ([ [1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]])NumPy a two-dimensional
This article mainly introduces the simple NumPy tutorial-array 2, which has some reference value. if you are interested, you can refer to it.
NumPy array (2. Array Operations)
Basic operations
Array arithmetic operations are per
Python Numpy array initialization and basic operations, pythonnumpy
Python is an advanced, dynamic, and multi-generic programming language. Python code often looks like pseudo code, so you can use a few lines of highly readable code to implement a very powerful idea.
I. Basics:
The main data type of Numpy is ndarray, which is a multi-dimensional
Tag:table using onelis array elements floating point floating point int fill NumPy is a scientific computing library of Python that provides the functions of matrix operations, which are generally used in conjunction with SCIPY and Matplotlib. In fact, the list already provides a matrix-like representation, but NumPy
], [ 2, 4]], [[ 3, 6], [ 4, 8], [ 5, 10]], [[ 6, 12], [ 7, 14], [ 8, 16]]])
After careful observation, it is found that the corresponding elements are combined into a new list, which serves as the elements of the new array.
Row combination
Row combination can combine multiple one-dimensional arrays as each row of the new array:
>>> one = arange(
The slice index of the array: The tile index of the array is very similar to the list, and the following code is a simple explanation
1A = Np.random.rand (+). Reshape (4, 4)2 Print("Array a:\n", a)3 Print(A[-1][1:4])4 out[1]: 5 Array A:6[0.04175379 0.43013992 0
NumPy is a basic module for the scientific calculation of Python. It is a Python library that provides a multidimensional array of objects, various derivative objects (such as shielded arrays and matrices), as well as various routines for array, math, logic, shape manipulation, sorting, selection, I/O and other fast operations, discrete Fourier transforms, basic
],
[6, 7, 8,,,]]]
#垂直组合
Np.vstack ((A, b))
'
Array ([[0, 1, 2],
[3, 4, 5], [
6, 7
, 8], [0, 2, 4], [6,,] [8, 12], ] "
#或者使用concatenate
con = np.concatenate ((A, B), axis=0)
#深度组合 Dstack (that is, the combination of the third axis (that is, the depth) of the array to generate a new list of arrays)
Np.dstack ((A, b)
NumPy mean (), STD () and other methods are acting on the entire numpy array, if it is a two-dimensional array, but also the entire array, including all the rows and columns, but we often need it only for rows or columns, rather than the entire two-dimensional
numpy Array (2, array operation)
Basic operations
The arithmetic operations of an array are calculated by element. The array operation creates a new array that contains the result of the operation.
>>> a= Np.array ([20,30,40,50
))
array ([[[0, 0],
[1, 2],
[2, 4]],
[[
3, 6], [4, 8], [5, 10]] ,
[[6],
[7],
[8, 16]]]
Careful observation shows that the corresponding elements are grouped together into a new list, which acts as an element of the new array.
Row combination
Row combinations can combine multiple one-dimensional arrays as each row of the new
NumPy Array (2, operation of Array)
Basic operations
An array is an arithmetic operation that is based on an element. An array operation creates a new array that contains the results of the operation.
>>> a= Np.array ([2
The Comparison Between Python list and NumPy. ndarry slice is described in detail,
Differences between Python list and NumPy. ndarry slices
Instance code:
# List slices return non-original data. Modifications to new data will not affect the original data In [45]: list1 =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.