1.将0-20的数据转化为一个列表 2.在这个列表中添加数据22, 33, 44. 55 3.将第一个元素修改为3.1415926 4.删除列表中第一个元素 5,批量删除下标为1.2,3的数据 6.移除20这个元素
时间: 2023-03-29 12:00:17 浏览: 67
1. [, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
2. [, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 33, 44, 55]
3. [3.1415926, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 33, 44, 55]
4. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 33, 44, 55]
5. [2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 33, 44, 55]
6. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 33, 44, 55]
相关问题
python读取excle中的数据后,将其中1,3,5列转化为转化为一个列表
IRuntime* runtime = createInferRuntime(gLogger);
engine = runtime->deserializeCudaEngine(
engineStream.str().data(), engineStream.str().size(), nullptr);
context = engine->createExecutionContext();
}
void loadModel(IBuilder*& builder, INetworkDefinition*& network) {
IParser* parser = createParser(*network, gLogger);
parser->parseFromFile(MODEL_FILE_PATH, static_cast<int>(Logger::Severity::kWARNING));
}
```
2. 创建输入和输出缓冲区
```c++
const int INPUT_H = 224;
const int INPUT_W = 224;
const int INPUT_C = 3;
const int BATCH_SIZE = 1;
void* inputBuffers[1];
void* outputBuffers[1];
void createInputOutputBuffer(IExecutionContext* context) {
int inputIndex = context->getEngine().getBindingIndex("input");
int outputIndex = context->getEngine().getBindingIndex("output");
cudaMalloc(&inputBuffers[inputIndex], BATCH_SIZE * INPUT_C * INPUT_H * INPUT_W * sizeof(float));
cudaMalloc(&outputBuffers[outputIndex], BATCH_SIZE * sizeof(float));
}
```
3. 加载输入照片到输入缓冲区
```c++
void loadInputImage(float* input, string imagePath) {
cv::Mat image = cv::imread(imagePath, cv::IMREAD_COLOR);
cv::Mat resizedImage;
cv::resize(image, resizedImage, cv::Size(INPUT_W, INPUT_H));
resizedImage.convertTo(resizedImage, CV_32FC3, 1.0f / 255.0f);
float* data = (float*)resizedImage.data;
int channels = resizedImage.channels();
for (int i = 0; i < INPUT_H; i++) {
for (int j = 0; j < INPUT_W; j++) {
for (int k = 0; k < channels; k++) {
input[k * INPUT_H * INPUT_W + i * INPUT_W + j] = *data++;
}
}
}
}
void loadInputImageToBuffer(IExecutionContext* context, string imagePath) {
int inputIndex = context->getEngine().getBindingIndex("input");
float* input = (float*)inputBuffers[inputIndex];
loadInputImage(input, imagePath);
}
```
4. 执行推理
```c++
void doInference(IExecutionContext* context) {
context->enqueue(BATCH_SIZE, inputBuffers, cudaStream_t{ 0 }, nullptr);
cudaStreamSynchronize(cudaStream_t{ 0 });
}
float* getOutput(IExecutionContext* context) {
int outputIndex = context->getEngine().getBindingIndex("output");
return (float*)outputBuffers[outputIndex];
}
```
5. 输出推理结果
```c++
void printOutput(float* output) {
cout << "Output: " << *output << endl;
}
```
完整的代码如下:
```c++
#include <iostream>
#include <fstream>
#include <sstream>
#include <cuda_runtime_api.h>
#include <NvInfer.h>
#include <NvOnnxParser.h>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace nvinfer1;
using namespace nvonnxparser;
static Logger gLogger;
const char* ENGINE_FILE_PATH = "path/to/engine/file";
const char* MODEL_FILE_PATH = "path/to/model好的,可以使用Python中的pandas库来读取Excel文件并提取指定列的数据,然后将这/file";
void loadEngineAndModel(IExecutionContext*& context, ICudaEngine*& engine) {
ifstream engineFile(ENGINE_FILE_PATH, ios些数据存储到一个列表中。下面是代码示例:
```python
import pandas as pd
# 读取Excel::binary);
stringstream engineStream;
engineStream << engineFile.rdbuf();
engineFile.close();
IRuntime* runtime =文件
df = pd.read_excel('your_file_path.xlsx')
# 提取指定列的数据
col1 = df.iloc[:, createInferRuntime(gLogger);
engine = runtime->deserializeCudaEngine(
engineStream.str().data(), engineStream.str().size(), nullptr);
context = engine->createExecutionContext();
}
void loadModel(IBuilder*& builder, INetworkDefinition*& network) {
0].tolist() # 第1列数据
col3 = df.iloc[:, 2].tolist() # 第3列数据
col5 = df.iloc[:, 4].tolist() # 第5列数据
# 将这些数据存储到一个列表中 IParser* parser = createParser(*network, gLogger);
parser->parseFromFile(MODEL_FILE_PATH, static_cast<int>(
result_list = [col1, col3, col5]
```
其中,`your_file_path.xlsx`是你要读取Logger::Severity::kWARNING));
}
const int INPUT_H = 224;
const int INPUT_W = 224;
const int INPUT_C = 3;
const int BATCH_SIZE = 1;
void* inputBuffers[1];
void* outputBuffers[1];
void createInputOutput的Excel文件的路径。`iloc`函数可以用来提取指定列的数据,`:,0`表示提取第1列的数据,`:,2`表示提取第3列的数据,`:,4`表示提取第5列的Buffer(IExecutionContext* context) {
int inputIndex = context->getEngine().getBindingIndex("input");
int outputIndex =数据。`tolist()`函数可以将提取的数据转化为列表。最后,将这些列表存储到一个列表 context->getEngine().getBindingIndex("output");
cudaMalloc(&inputBuffers[inputIndex], BATCH_SIZE * INPUT_C * INPUT_H中,即可得到所需的结果。
在python中如何将一个列表数据转化为dataframe数据
可以使用 pandas 库中的 DataFrame 方法将列表数据转化为 dataframe 数据。例如,如果列表数据为 a = [1, 2, 3, 4],则可以使用以下代码将其转化为 dataframe 数据:
import pandas as pd
df = pd.DataFrame(a, columns=['列名'])
其中 '列名' 是新 dataframe 中列的名称。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)