Skip to main content

All Questions

Tagged with
0 votes
1 answer
243 views

What is the fastest way to find the average for a list of tuples in Python, each tuple containing a pair of namedtuples?

import numpy as numpy from collections import namedtuple from random import random Smoker = namedtuple("Smoker", ["Female","Male"]) Nonsmoker = namedtuple("...
Paw in Data's user avatar
  • 1,432
3 votes
4 answers
2k views

How do I use sum()/average() for namedtuple in python?

from collections import namedtuple Point = namedtuple('Point', ['x', 'y']) points = [Point(x=1.0, y=1.0), Point(x=2.0, y=2.0)] I'd like to compute the average point out of points list, i.e. receive ...
Alex's user avatar
  • 599
1 vote
1 answer
4k views

Writing a numpy.array() from a list of namedtuples

I have a list of namedtuples which I would like to write to a numpy array. The tuples have attributes 'colors', a set of two colors, and 'number', an integer, and are of the form: from collections ...
Zero's user avatar
  • 33
2 votes
1 answer
1k views

Create instances of namedtuples as database records with loop

I was wondering whether it is possible to instantiate namedtuples within a loop. The problem I am having is that I have individual files (>500), which each should be an instance of a namedtuple and I ...
hyst111's user avatar
  • 21
6 votes
2 answers
6k views

Namedtuple in Numpy

I really like the functionally of the namedtuple collection. Specifically I like how useful it is for points in 2-dimensional space. In : from collections import namedtuple In : Point = namedtuple('...
Ben's user avatar
  • 4,934
1 vote
2 answers
2k views

initialize numpy array with named tuples

I'm trying to initialize a NumPy array that contains named tuples. Everything works fine when I initialize the array with empty data and set that data afterwards; when using the numpy.array ...
Nico Schlömer's user avatar
11 votes
4 answers
4k views

Equivalent of named tuple in NumPy?

Is it possible to create a NumPy object that behaves very much like a collections.namedtuple, in the sense that elements can be accessed like so: data[1] = 42 data['start date'] = '2011-09-20' # ...
Eric O. Lebigot's user avatar