Recently, when we started to understand image recognition, we’ve certainly used deep learning frameworks, and we’ve also seen a new data structure called tensor. In addition, there are also some commonly used data structures, such as DataFrame, Series, array, etc. This article mainly summarizes the creation and conversion of these data structures. \

Create method

DataFrame

Instead of Posting individual sample diagrams of each data structure, I will simply describe the characteristics of each data structure. A DataFrame is like a two-dimensional matrix, but its columns and columns have corresponding indexes.

There are many ways to create a DataFrame. Here are three common methods:

1. Create a dictionary

2. Create by tuple

The principle is the same as that of creating a dictionary, but the row and column indexes must be specified by yourself.

3. Randn is generated randomly

Np.random. Randn (m,n) is a matrix that generates a specification, and the column and column indexes need to be specified themselves.

Series

A Series can be thought of as an element in a DataFrame, with a column of values for each index.

1. Create a dictionary

2. Create from a list

3. Create it using arange

array

tensor

So Tensor is a class, Tensor and as_tensor are methods, and the first one will generate floating-point numbers, and then the other two will generate the same kind of numbers that you put in, which means that when you put in integers you get integers, when you put in floating-point numbers you get floating-point numbers. \

conversion

DataFrame and dismantling Series

A single row or column is of type Series. \

Turn DataFrame array

1. Obtain values directly

2, through numpy conversion

The Series turn DataFrame

1, synthesis

2. To_frame () method

The Series turn array

Convert DataFrame to array.

\

Turn array DataFrame

Turn array Series

Turn array tensor

Turn tensor array

The above creation and transformation methods are only a part of the more common, in addition to the list can also be used as an intermediate medium for conversion, and so on, here is not too much introduction. \

Python Chinese community as a decentralized global technology community, to become the world’s 200000 Python tribe as the vision, the spirit of Chinese developers currently covered each big mainstream media and collaboration platform, and ali, tencent, baidu, Microsoft, amazon and open China, CSDN industry well-known companies and established wide-ranging connection of the technical community, Have come from more than 10 countries and regions tens of thousands of registered members, members from the ministry, tsinghua university, Peking University, Beijing university of posts and telecommunications, the People’s Bank of China, the Chinese Academy of Sciences, cicc, huawei, BAT, such as Google, Microsoft, government departments, scientific research institutions, financial institutions, and well-known companies at home and abroad, nearly 200000 developers to focus on the platform.

Long press scan to add “Python Assistant”

Click here to become a community member