tuples

to slice columns in a tuple present in a numpy array

左心房为你撑大大i 提交于 2019-12-07 12:35:41
问题 I have imported a text file into a numpy array as shown below. data=np.genfromtxt(f,dtype=None,delimiter=',',names=None) where f contains the path of my csv file now data contains the following. array([(534, 116.48482, 39.89821, '2008-02-03 00:00:49'), (650, 116.4978, 39.98097, '2008-02-03 00:00:02'), (675, 116.31873, 39.9374, '2008-02-03 00:00:04'), (715, 116.70027, 40.16545, '2008-02-03 00:00:45'), (2884, 116.67727, 39.88201, '2008-02-03 00:00:48'), (3799, 116.29838, 40.04533, '2008-02-03

Adding an entry to a python tuple

别来无恙 提交于 2019-12-07 12:03:09
问题 I have a list of tuples representing x,y points. I also have a list of values for each of these points. How do I combine them into a list of lists (i.e one entry for each point [x,y,val]) or a list of tuples? Thanks 回答1: You can't add entries to tuples, since tuples are immutable. But you can create a new list of lists: new = [[x, y, val] for (x, y), val in zip(points, vals)] 回答2: Tuples are immutable, they can't be modified. Convert it to a list, then convert it back if you want to (list((a,

How to get the index of an element in a tuple via address?

烂漫一生 提交于 2019-12-07 11:18:09
问题 For example: std::tuple<int, double> t; void* p = &std::get<1>(t); Now I want to get p's index by some function like template<typename... Ts> size_t index(void* p, std::tuple<Ts...> const& t) { ... } Sure the result is 1 for this example. I am interested in how to implement the function to get the index when p is obtained by ways other than the explicit index. 回答1: Something you do not need in C++14, a mini indexes library: template<unsigned...>struct indexes{using type=indexes;}; template

slick error : type TupleXX is not a member of package scala (XX > 22)

浪尽此生 提交于 2019-12-07 09:32:08
问题 I want to write a database schema using lifted slick. I have huge tables with more than 100 columns. So i have this error for all the tables that exceed 22 columns : type Tuple45 is not a member of package scala Here is the code of one of the tables : object adrepost extends Table[(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, Date, Boolean, Date, Int, Boolean, String, String, String, String, String,

pymssql: executemany value error - expected a simple type, a tuple or a list

我与影子孤独终老i 提交于 2019-12-07 08:25:19
问题 grpidx_data=[] for i in range(0,len(data1)): grpidx_data.append((data1.loc[i,'price'],data1.loc[i,'id'])) cur.executemany("insert into grpidx values (%s,%s)",grpidx_data) I use python3.3 and pymssql. I want to import data from python to MSSQL. grpidx_data's type is list(tuple) ,like[(12,1),(34,2),...], I run the code above then got the error: ValueError: expected a simple type, a tuple or a list If I just use the data which type is list(tuple) , the code works fine. But when I use for loop

create a series of tuples using a for loop

夙愿已清 提交于 2019-12-07 07:32:33
问题 I have searched and cannot find the answer to this even though I am sure it is already out there. I am very new to python but I have done this kind of stuff before in other languages, I am reading in line form a data file and I want to store each line of data in it's own tuple to be accessed outside the for loop. tup(i) = inLine where inLine is the line from the file and tup(i) is the tuple it's stored in. i increases as the loop goes round. I can then print any line using something similar

Convert list of of objects to list of tuple without iterating

回眸只為那壹抹淺笑 提交于 2019-12-07 07:29:17
问题 I'm trying to add an extra parameter to a list of ef objects to track processing, but I keep running into having to initialize each list item explicitly. What's the correct linq way to do this? Aside from terseness, is there any advantage to a linq syntax in this case? List<app_subjects> subjectList = AppMySQLQueries.GetAllSubjects(); List<Tuple<app_subjects, bool>> subjectCollection = new List<Tuple<app_subjects, bool>>(subjectList.Count); foreach (app_subjects subject in subjectList) {

Triples in Java [duplicate]

与世无争的帅哥 提交于 2019-12-07 07:13:14
问题 This question already has answers here : Using Pairs or 2-tuples in Java [duplicate] (14 answers) Closed 3 years ago . Possible Duplicate: Does Java need tuples? Does Java support triples or at least pairs? Does Java support tuples? I am trying to find a way to make a list so that it has a triple with initial point as first, terminal point at last, and distance in the middle. However, I can't seem to find anything about it. 回答1: I usually just create my own class for these purposes. class

How to convert a tuple to a string in Python?

霸气de小男生 提交于 2019-12-07 07:08:26
问题 After a MySQL select statement, I am left with the following: set([('1@a.com',), ('2@b.net',), ('3@c.com',), ('4@d.com',), ('5@e.com',), ('6@f.net',), ('7@h.net',), ('8@g.com',)]) What I would like to have is a emaillist = "\n".join(queryresult) to in the end, have a string: 1@a.com 2@b.net 3@c.com etc What would be the proper way to convert this nested tuple into string? 回答1: As long as you're sure you have just one element per tuple: '\n'.join(elem[0] for elem in queryresult) 回答2: A list

Overloading + to support tuples

99封情书 提交于 2019-12-07 06:28:54
问题 I'd like to be able to write something like this in python: a = (1, 2) b = (3, 4) c = a + b # c would be (4, 6) d = 3 * b # d would be (9, 12) I realize that you can overload operators to work with custom classes, but is there a way to overload operators to work with pairs? Of course, such solutions as c = tuple([x+y for x, y in zip(a, b)]) do work, but, let aside performance, they aren't quite as pretty as overloading the + operator. One can of course define add and mul functions such as def