Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66790 > unrolled thread
| Started by | Jaydeep Patil <patil.jay2009@gmail.com> |
|---|---|
| First post | 2014-02-20 22:31 -0800 |
| Last post | 2014-02-21 06:28 -0500 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
TypeError: can't multiply sequence by non-int of type 'tuple' Jaydeep Patil <patil.jay2009@gmail.com> - 2014-02-20 22:31 -0800
Re: TypeError: can't multiply sequence by non-int of type 'tuple' Rustom Mody <rustompmody@gmail.com> - 2014-02-20 22:36 -0800
Re: TypeError: can't multiply sequence by non-int of type 'tuple' Jaydeep Patil <patil.jay2009@gmail.com> - 2014-02-20 22:41 -0800
Re:TypeError: can't multiply sequence by non-int of type 'tuple' Dave Angel <davea@davea.name> - 2014-02-21 06:28 -0500
| From | Jaydeep Patil <patil.jay2009@gmail.com> |
|---|---|
| Date | 2014-02-20 22:31 -0800 |
| Subject | TypeError: can't multiply sequence by non-int of type 'tuple' |
| Message-ID | <e84de2c2-5333-42ae-ae22-cf628c177ae1@googlegroups.com> |
HI,
I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came.
Code:
seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,))
x2 = [x * x for x in seriesxlist1];
Error:
Traceback (most recent call last):
File "<pyshell#188>", line 1, in <module>
x2 = [x * x for x in seriesxlist1];
TypeError: can't multiply sequence by non-int of type 'tuple'
Please suggest me solution.
[toc] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-02-20 22:36 -0800 |
| Message-ID | <66307663-a47a-48ed-ac1d-1cf4703b9c48@googlegroups.com> |
| In reply to | #66790 |
On Friday, February 21, 2014 12:01:53 PM UTC+5:30, Jaydeep Patil wrote: > HI, > I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came. > Code: > seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,)) > x2 = [x * x for x in seriesxlist1]; > Error: > Traceback (most recent call last): > x2 = [x * x for x in seriesxlist1]; > TypeError: can't multiply sequence by non-int of type 'tuple' > Please suggest me solution. >>> x2 = [x * x for (x,) in seriesxlist1] >>> x2 [0.0, 0.0001, 0.0004, 0.0009, 0.0016, 0.0025000000000000005, 0.0036, 0.004900000000000001, 0.0064, 0.0081, 0.010000000000000002, 0.0121] >>> 1 Why you are making singleton tuples dunno 2 And no need for semicolons in python
[toc] | [prev] | [next] | [standalone]
| From | Jaydeep Patil <patil.jay2009@gmail.com> |
|---|---|
| Date | 2014-02-20 22:41 -0800 |
| Message-ID | <aef97ff3-8719-4e90-bf61-794f4ab6a871@googlegroups.com> |
| In reply to | #66791 |
On Friday, 21 February 2014 12:06:54 UTC+5:30, Rustom Mody wrote: > On Friday, February 21, 2014 12:01:53 PM UTC+5:30, Jaydeep Patil wrote: > > > HI, > > > > > I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came. > > > > > Code: > > > seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,)) > > > > > x2 = [x * x for x in seriesxlist1]; > > > > > Error: > > > Traceback (most recent call last): > > > x2 = [x * x for x in seriesxlist1]; > > > TypeError: can't multiply sequence by non-int of type 'tuple' > > > > > > > Please suggest me solution. > > > > >>> x2 = [x * x for (x,) in seriesxlist1] > > >>> x2 > > [0.0, 0.0001, 0.0004, 0.0009, 0.0016, 0.0025000000000000005, 0.0036, 0.004900000000000001, 0.0064, 0.0081, 0.010000000000000002, 0.0121] > > >>> > > > > 1 Why you are making singleton tuples dunno > > 2 And no need for semicolons in python Answer: 1. This tupple, i get it from excel range extraction. e.g. seriesxlist = newws.Range(newws.Cells(3,2),newws.Cells(usedRows,2)).Value 2. i removed semicolon, still i am facing same error. I am unable to get multiplies values. Please suggest. I have input as below tuple only. seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,))
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-02-21 06:28 -0500 |
| Message-ID | <mailman.7224.1392981874.18130.python-list@python.org> |
| In reply to | #66790 |
Jaydeep Patil <patil.jay2009@gmail.com> Wrote in message: > HI, > > I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came. > > > Code: > seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,)) > > x2 = [x * x for x in seriesxlist1]; > > Error: > Traceback (most recent call last): > File "<pyshell#188>", line 1, in <module> > x2 = [x * x for x in seriesxlist1]; > TypeError: can't multiply sequence by non-int of type 'tuple' > The cause of the error is easy enough. (0.0,) * (0.0,) is undefined. It's unclear however what you actually intended because the problem is incompletely specified. Start with python version. I'll assume 3.3. Next show us what result you actually expect. Can we assume all tuples will have a single element in them? Are you looking to flatten both list and tuples, and get a single float sum? Wild guess: x2 = [x[0]* x[0] for x in seriesxlist1]; res = sum (x2) -- DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web