来自两个数组的Python linspace限制 [英] Python linspace limits from two arrays

查看:73
本文介绍了来自两个数组的Python linspace限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组:

a=np.array((1,2,3,4,5))
b=np.array((2,3,4,5,6))

我想要的是将a和b的值用于linspace的限制,例如

What I want is to use the values of a and b for the limits of linspace e.g.

c=np.linspace(a,b,11)

使用此代码时出现错误.答案应该是数组的第一个元素:

I get an error when I use this code. The answer should be for the first element of the array:

c=np.linspace(a,b,11)
print c
c=[1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2]

推荐答案

您可以执行以下操作:

c = np.array([np.linspace(i,j,5) for i,j in zip(a,b)])

#array([[ 1.  ,  1.25,  1.5 ,  1.75,  2.  ],
#       [ 2.  ,  2.25,  2.5 ,  2.75,  3.  ],
#       [ 3.  ,  3.25,  3.5 ,  3.75,  4.  ],
#       [ 4.  ,  4.25,  4.5 ,  4.75,  5.  ],
#       [ 5.  ,  5.25,  5.5 ,  5.75,  6.  ]])

这篇关于来自两个数组的Python linspace限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆