本文介绍了一致性:扩展数组与乘法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 刚刚开始使用python,我觉得简单的数组操作''''' 和''+''不进行乘法/加法,而是扩展/加入 数组: a = [1,2,3] [1,2,3,1,2,3] 嗯,它与字符串一致但是容忍字符串操作是 特殊对我来说是好的,因为a +b - > ''ab'':) 为什么不让它成为另一个函数,比如a.stretch()或a.expand()和 a.extend()在做什么无论如何都是相同的,并且更具可读性... 将它放在更大的视图中: Ufuncs是非常合理的罪(a)等...所有这些都不会奏效,因为 的'+'','''''语法。好的我可以使用numarray,但是看到它的 PEP并且可能包含在python中某些时候 的不一致让我非常头疼... 将来会改变吗?或者这个100 * [0]语法是否适用于所有年龄段的 石头? 最佳, Soeren。 PS:因为我对python很新,请原谅/纠正我! 解决方案 [1,2,3,4,5,6] 两者都在列表本身上运行,而不是在内容上运行。很好 如果你问我一致。 Ciao, Marc''BlackJack''Rintsch [1,2,3,4,5,6] 而不是我的预期: [5,7,9] 为了得到你的预期,请使用 [x + y代表(x,y)的拉链(a,b)] Hi all,Just having started with python, I feel that simple array operations ''*''and ''+'' don''t do multiplication/addition but instead extend/join anarray:a=[1,2,3][1, 2, 3, 1, 2, 3]Well it is consistent to strings but tolerating string-operations to bespecial is ok to me as "a" + "b" -> ''ab'' :)Why not make it another function like a.stretch() or a.expand() anda.extend() is there doing the same anyway and is more readable...Putting this in a larger view:Ufuncs are very reasonable sin(a), etc ... all that won''t work becauseof that ''+'',''*'' syntax. Ok I can use numarray for that, but seeing itsPEP and a possible inclusion into python at some point thatinconsistency is giving me quite some headache...Will that change in the future ? Or is this 100*[0] syntax put intostone for all ages ?Best,Soeren.PS: As I am very new to python please forgive/correct me! 解决方案 [1, 2, 3, 4, 5, 6]Both operate on the lists themselves and not on their contents. Quiteconsistent if you ask me.Ciao,Marc ''BlackJack'' Rintsch* and + are not array operations, they are list operations.Lists in Python can contain anything, not just numeric values.Python doesn''t have built-in mathematical arrays, otherwise known asmatrices. There are modules that do that, but I haven''t used them. Googleon Numeric Python.--Steven. [1, 2, 3, 4, 5, 6] instead of what I would have expected: [5,7,9]To get what you expected, use[x + y for (x, y) in zip(a, b)] 这篇关于一致性:扩展数组与乘法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 04:57