Python np.array示例,如何修改/?

2024-05-16 09:29:05 发布

您现在位置:Python中文网/ 问答频道 /正文

在两个不同的文件中,我应用了相同的代码

import numpy as np

a = check[0:30]
**print(a)**
ai = [[item[1] for item in check[0:30]]]
a1 = np.array(ai)
**print(a1.shape)**
a2 = np.reshape(a1,(-1,))
**print(a2.shape)**
a = list(a2)

但答案不同

第一个答案如下

[['grind'], ['fracture'], ['edge'], ['instal'], ['protection'], ['transport'], ['injuries'], ['head'], ['sustain'], ['remove'], ['use'], ['step'], ['die'], ['skylight'], ['walk'], ['ladder', 'treat'], ['lose'], ['company'], ['emergency'], ['employees'], ['open'], ['roofer'], ['break'], ['land'], ['call'], ['back'], ['employ'], ['balance'], ['suffer'], ['material']]

(1, 30)
(30,)

第二个看起来像

['ladder', 'fracture', 'grind', 'build', 'transport', 'concrete', 'instal', 'injuries', 'head', 'use', 'treat', 'sustain', 'edge', 'company', 'employees', 'metal', 'remove', 'emergency', 'protection', 'die', 'floor', 'leave', 'call', 'slip', 'skylight', 'employ', 'admit', 'step', 'back', 'lose']

(30, 1)
(30,)

我想把np.array改成第二个。 我该如何更改代码


Tags: 答案代码a2checka1npitemarray