我可以使用数组切片而不是创建向量吗?

2024-03-29 12:50:39 发布

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

这不是作业! 复杂问题的简单例子。 现在我取数组,创建向量,然后用向量作为输入的等式。 一切正常。但是,我想知道我是否可以跳过向量创建,并使用数组切片到相同的东西。你知道吗

import numpy as np

a = [[ 7.,  5.], [ 9.,  3.], [ 7.,  2.], [ 7.,  8.], [ 6.,  8.], [ 3.,  2.]]
a = np.asarray(list(a), np.float)

x = np.asarray(a[:,(0)], np.float)
y = np.asarray(a[:,(1)], np.float)

foo = 5*x+y*y 
print foo 

Tags: importnumpyfooasnp作业切片数组