列表:将Double转换为Single [英] Lists: Converting Double to Single

查看:275
本文介绍了列表:将Double转换为Single的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个从数据库表中检索的元组列表开始。这些

元组被提取并放入单独的列表中。所以我列出了

看起来像这样:[1,2,3,4,5]。当我连接列表时,我最终会得到一个

列表,如下所示:[[1,2,3,4,5]。 [6,7,8,9。10]]。

然后,我平均列值,所以我最终得到一个列表,但是

两个括号每一端,例如[[3.5,4.5,5.5,6.5,7.5]]。


不幸的是,当我尝试在NumPy函数中使用最后一个列表时,我'' m

告诉它无法播放到正确的形状。那么,我想要做什么

从每一端剥去额外的托架,只留下[3.5,4.5,5.5,6.5,

7.5]。


我该怎么办?


Rich

解决方案

rs******@nospam.appl-ecosys.com 写道:
< blockquote class =post_quotes>
所以我的列表看起来像这样:[1,2,3,4,5]。当我将
连接列表时,我最终会得到一个列表,看起来像是这样的:[[1,2,3,4,5]。 [6,7,8,9。10]]。



真的吗?


>> [1,2,3,4,5] + [6 ,7,8,9,10]



[1,2,3,4,5,6,7,8, 9,10]


然后,我平均列值,所以我最终得到一个列表,但

每个都有两个括号结束,例如,[[3.5,4.5,5.5,6.5,

7.5]]。


不幸的是,当我尝试使用最后一个列表时一个NumPy函数,

我被告知它无法播放到正确的形状。所以,我想要做的就是从每一端剥去额外的托架,只留下
[3.5,4.5,5.5,6.5,7.5]。



l = l [0]


rs ****** @ nospam.appl-ecosys.com 写道:


我最终得到一个列表,但每端有两个括号,例如,
,[[3.5,4.5,5.5,6.5,7.5]]。


不幸的是,当我尝试在NumPy

函数中使用最后一个列表时,我告诉它不能广播到正确的形状。所以,我想要做的就是从每一端剥去额外的托叶,只留下
[3.5,4.5,5.5,6.5,7.5]。


我该怎么办呢?



轻松:)


我会举例告诉你:


>> ham = [[1,2,3],[4,5,6]]
ham



[[1,2,3],[4,5,6]]


>> ham [0]



[1,2,3]


>> ham。删除([4,5,6])
ham [0]



[1,2,3]


>> ham



[[1,2,3]]


>>>



HTH& Regards,

Bj?


-

BOFH借口#453:



2007-02-27,Leif K-Brooks< eu ***** @ ecritters.bizwrote:


Lief,Bjoern:


l = l [0]



当然!如果我在一夜之间让它在我的脑海里工作,我几乎可以肯定地看到了这个。


感谢你们的耐心反应,


Rich


I start with a list of tuples retrieved from a database table. These
tuples are extracted and put into individual lists. So I have lists that
look like this: [1, 2, 3, 4, 5]. When I concatenate lists, I end up with a
list of lists that looks like this: [[1, 2, 3. 4, 5]. [6, 7. 8, 9. 10]].
Then, I average the column values so I end up with a single list, but with
two brackets on each end, for example, [[3.5, 4.5, 5.5, 6.5, 7.5]].

Unfortunately, when I try to use that last list in a NumPy function, I''m
told that it cannot be broadcast to the correct shape. So, what I want to do
is strip the extra brackes from each end to leave just [3.5, 4.5, 5.5, 6.5,
7.5].

How do I do this, please?

Rich

解决方案

rs******@nospam.appl-ecosys.com wrote:

So I have lists that look like this: [1, 2, 3, 4, 5]. When I
concatenate lists, I end up with a list of lists that looks like
this: [[1, 2, 3. 4, 5]. [6, 7. 8, 9. 10]].

Really?

>>[1, 2, 3, 4, 5] + [6, 7, 8, 9, 10]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Then, I average the column values so I end up with a single list, but
with two brackets on each end, for example, [[3.5, 4.5, 5.5, 6.5,
7.5]].

Unfortunately, when I try to use that last list in a NumPy function,
I''m told that it cannot be broadcast to the correct shape. So, what I
want to do is strip the extra brackes from each end to leave just
[3.5, 4.5, 5.5, 6.5, 7.5].

l = l[0]


rs******@nospam.appl-ecosys.com wrote:

I end up with a single list, but with two brackets on each end,
for example, [[3.5, 4.5, 5.5, 6.5, 7.5]].

Unfortunately, when I try to use that last list in a NumPy
function, I''m
told that it cannot be broadcast to the correct shape. So, what I
want to do is strip the extra brackes from each end to leave just
[3.5, 4.5, 5.5, 6.5, 7.5].

How do I do this, please?

Easy :)

I''ll show you by example:

>>ham = [[1,2,3],[4,5,6]]
ham

[[1, 2, 3], [4, 5, 6]]

>>ham[0]

[1, 2, 3]

>>ham.remove([4,5,6])
ham[0]

[1, 2, 3]

>>ham

[[1, 2, 3]]

>>>

HTH&Regards,
Bj?rn

--
BOFH excuse #453:

Spider infestation in warm case parts


On 2007-02-27, Leif K-Brooks <eu*****@ecritters.bizwrote:

Lief, Bjoern:

l = l[0]

Of course! If I had let it work in my mind overnight I would almost
certainly have seen this.

Thank you both for your patient responses,

Rich


这篇关于列表:将Double转换为Single的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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