我有一个python列表
const data = {"lesseeName":"Padyster-7","lesseeRegNo":"12345","lesseeVatNo":"4456","telFaxNo":"1234567891","billingAddress":{"addressId":null,"addressLine1":"XYz , l1 street","addressLine2":"near xyz bank","postalCode":"60000","countryName":"MY","cityName":"Kuala lumpur","stateProvinceCode":"Kuala lumpur"},"mlaList":[{"mlaNo":92,"lesseeId":108,"executionDate":"27/01/2017","signatoryInfo":"Test","overdueRate":3.44,"nonPaymentDays":2,"consolidationTerm":"Monthly","createdBy":null,"createdDtm":null,"updatedBy":null,"updatedDtm":null,"statusIndicator":null,"signatoryEmail":"tooot@gmail.com","leaseMlaNo":"OPM1","statusDescription":"APPROVED"},{"mlaNo":93,"lesseeId":108,"executionDate":"03/01/2017","signatoryInfo":"tess","overdueRate":5.77,"nonPaymentDays":2,"consolidationTerm":"Bi-Monthly","createdBy":null,"createdDtm":null,"updatedBy":null,"updatedDtm":null,"statusIndicator":null,"signatoryEmail":"xyz@gmail.com","leaseMlaNo":"OPM2","statusDescription":"APPROVED"}]};
const list = data.mlaList.map(val => `${val.leaseMlaNo} ${val.signatoryEmail}`);
console.log(list)
我需要创建一个像
这样的数组l = [1,2,3,4,5]
以便我可以使用
进行比较y_pred = array('B', [1, 2, 3, 4, 5])
我尝试使用
进行操作print accuracy_score(y_test, y_pred)
但它正在显示
TypeError:数据类型不理解
答案 0 :(得分:0)
构造结构化数组时需要提供dtype
参数。请参阅:structured arrays。
import numpy as np
x = np.array([(1,2.,'Hello'), (2,3.,"World")],
dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')])
我完全不知道你要做什么,但也许就是这样:
import numpy as np
l = [1,2,3,4,5]
y_pred = np.array(np.array(l),dtype=[('B',np.int32)])
# >>> y_pred
# array([(1,), (2,), (3,), (4,), (5,)],
# dtype=[('B', '<i4')])
答案 1 :(得分:0)
首先np.array
采用类似列表和dtype
的对象。
在,
array('B', [1, 2, 3, 4, 5])
以'B'作为对象,但[1,2,3,...]
不符合dtype
的条件。
列表中的简单数组是:
In [15]: np.array([1,2,3,4,5])
Out[15]: array([1, 2, 3, 4, 5])
你说你想要structured array
。但为了使你需要指定一个化合物dtype
,数据必须是一个匹配的元组列表。
In [14]: np.array([("B", 2), ("C", 3)], dtype='S5,int')
Out[14]:
array([(b'B', 2), (b'C', 3)],
dtype=[('f0', 'S5'), ('f1', '<i4')])
但该结构与您的数据,一个字符串和一个包含5个数字的列表不匹配。你想要一个包含1行(记录)或5行的数组吗?
如果要将y_pred
与另一个数组进行比较,则需要匹配其dtype和形状。什么是y_test
?