Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

UberJumper posted:

Does anyone know how exactly comtypes rips out all the CLSID information out from COM automon files?

I have no idea what/how comtypes works, but have you tried looking at the source?
this seems to parse some sort of file and sets clsid on the ones that are of a certain type (CoClass).

Adbot
ADBOT LOVES YOU

dis astranagant
Dec 14, 2006

How would I write something like
code:
foo[][] result = new foo[x][y]();
//initialization and edge cases cut
for (int i=0; i<x; i++)
    for (int j=0; j<y; j++)
        if (result[i-1][j] == 0  || result[i][j-1] == 0)
            doStuff();
        else
            doOtherStuff();
in python? As far as I can tell, for loops in Python only work on ranges and collections, with no way of getting the loop counter. Plus there's the can of worms that is making a 2D list (I have a function for that already).

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

dis astranagant posted:

How would I write something like
code:
foo[][] result = new foo[x][y]();
//initialization and edge cases cut
for (int i=0; i<x; i++)
    for (int j=0; j<y; j++)
        if (result[i-1][j] == 0  || result[i][j-1] == 0)
            doStuff();
        else
            doOtherStuff();
in python? As far as I can tell, for loops in Python only work on ranges and collections, with no way of getting the loop counter. Plus there's the can of worms that is making a 2D list (I have a function for that already).

code:
for i in xrange(x):
    for j in xrange(y):
        ...

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

dis astranagant posted:

Plus there's the can of worms that is making a 2D list

There's no such thing. (PS use NumPy)

Benji the Blade
Jun 22, 2004
Plate of shrimp.

dis astranagant posted:

Plus, there's the can of worms that is making a 2D list (I have a function for that already).

Can of worms?

code:
[[0] * y for _ in range(x)]

wins32767
Mar 16, 2007

A A 2 3 5 8 K posted:

code:
for i in xrange(x):
    for j in xrange(y):
        ...

Or alternately
code:
for i, foo in enumerate(x):
    for j, bar in enumerate(y):
        ...
depending on what you want to do.

dis astranagant
Dec 14, 2006

wins32767 posted:

Or alternately
code:
for i, foo in enumerate(x):
    for j, bar in enumerate(y):
        ...
depending on what you want to do.

Yeah, don't know how I was that blind last night. As for the 2d list thing, I'm still in that stage where every feature that's not what I'm used to sucks. Granted, lists are created and accessed just like the arrays in pretty much every other language, 2d lists (once created) are accessed exactly like them and yet I can't create a 2d list just by going foo[x][y]=blah.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

dis astranagant posted:

Yeah, don't know how I was that blind last night. As for the 2d list thing, I'm still in that stage where every feature that's not what I'm used to sucks. Granted, lists are created and accessed just like the arrays in pretty much every other language, 2d lists (once created) are accessed exactly like them and yet I can't create a 2d list just by going foo[x][y]=blah.

I don't really understand what you're saying. You can't create a normal list by going foo[x]=blah either. You could use a dictionary if you really want to do that sort of thing I suppose, but you'd be pretty crazy to do that for small matrices.

dis astranagant
Dec 14, 2006

err, more like foo = [1,2,3][4,5,6]. foo[x][y] is how you access it.

BigRedDot
Mar 6, 2008

Seriously, if you want 2D arrays that have features, you should use numpy as already suggested.

http://www.scipy.org/Tentative_NumPy_Tutorial

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

And if you can't justify using Numpy, or have no use for the features it gives you, then you probably don't need to be using matrices anyway.

dis astranagant
Dec 14, 2006

Sailor_Spoon posted:

And if you can't justify using Numpy, or have no use for the features it gives you, then you probably don't need to be using matrices anyway.

I wasn't actually using matrices. I was just trying to make a dull ":downsbravo: you paid attention during the dynamic programming review" assignment in my bioinformatics class more interesting by taking the professor up on being able to turn in assignments in any programming language. Didn't feel like going too screwy, so I went with python.

tripwire
Nov 19, 2004

        ghost flow

dis astranagant posted:

I wasn't actually using matrices. I was just trying to make a dull ":downsbravo: you paid attention during the dynamic programming review" assignment in my bioinformatics class more interesting by taking the professor up on being able to turn in assignments in any programming language. Didn't feel like going too screwy, so I went with python.

Trust me, check out numpy. It will make your life incredibly easy if you are doing any sort of numerical work in python, and performance wise its a very easy way to make python competitive with more low-level languages while still retaining a very powerful high level interface.

Scaevolus
Apr 16, 2007

Just learned that ending files with .pyw lets you run them without the console on Windows. :downs:

I'm really enjoying PyQt4. You use the Qt Designer to define the layout and write boilerplate, then you can just work with the guts. Do any of the other UI toolkits have WYSIWYG UI designers?

Scaevolus fucked around with this message at 22:19 on Jan 23, 2010

Ferg
May 6, 2007

Lipstick Apathy

Scaevolus posted:

Just learned that ending files with .pyw lets you run them without the console on Windows. :downs:

I'm really enjoying PyQt4. You use the Qt Designer to define the layout and write boilerplate, then you can just work with the guts. Do any of the other UI toolkits have WYSIWYG UI designers?

I use Glade for PyGTK programming. There's also Gazpacho on Linux for GTK.

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
Anyone know if there is a easy way to do gravity rotations for vertical text in pygtk-pango? I can do it using c, but I can not find the bindings for Matrix and gravity stuff in the python bindings.

maskenfreiheit
Dec 30, 2004
Edit: doublepost

maskenfreiheit fucked around with this message at 01:22 on Mar 13, 2017

MaberMK
Feb 1, 2008

BFFs

GregNorc posted:

Is there a way to quickly make a GUI python program?

Like, some sort of drag and drop tool? It doesn't have to be complex, I'm just looking at making a little app that would work better with a GUI than on the command line, but haven't really done any gui programming yet... I'd like to avoid a situation where coding the GUI ends up taking longer than the actual program's code.

PyQT and PyGTK are probably your best bet. The designer applications for each (Glade, QT Designer) will generate XML descriptions of the UI that you then load in Python. You'll write relatively little UI code in Python and work mostly with application logic.

Scaevolus
Apr 16, 2007

GregNorc posted:

Is there a way to quickly make a GUI python program?

Like, some sort of drag and drop tool? It doesn't have to be complex, I'm just looking at making a little app that would work better with a GUI than on the command line, but haven't really done any gui programming yet... I'd like to avoid a situation where coding the GUI ends up taking longer than the actual program's code.

PyQt is really easy.

http://diotavelli.net/PyQtWiki/Creating_GUI_Applications_with_PyQt_and_Qt_Designer

General procedure:
1) Use Qt Designer to design your UI. It's WYSIWYG and very easy to use.
2) Run pyuic4 on the .ui file created by Designer, generating a Python module that sets up the GUI.
3) Write a main python file that subclasses the generated UI module and add logic.

Ferg
May 6, 2007

Lipstick Apathy

GregNorc posted:

Is there a way to quickly make a GUI python program?

Like, some sort of drag and drop tool? It doesn't have to be complex, I'm just looking at making a little app that would work better with a GUI than on the command line, but haven't really done any gui programming yet... I'd like to avoid a situation where coding the GUI ends up taking longer than the actual program's code.

If you're running Ubuntu, this is the easiest method to get up and running: https://wiki.ubuntu.com/Quickly

2 + 2 = 5
Apr 11, 2003
I find it decidedly INCONVENIENT that the gun was never found.
I'm trying to figure out how to add up all the integers in a list (or recursively all the lists it contains). I think the idea of the assignment is to base it on Ackermann's function (with the stipulation of no loops):
code:
def ackermann(i, j):
    if i == 0:
        return j + 1
    elif j == 0:
        return ackermann(i - 1, 1)
    else:
        return ackermann(i - 1, ackermann(i, j - 1))
Here's what I have for my function.

code:
def sum_ints(x):
    global counter
    if isinstance(x, int):
        return x
    elif isinstance(x, list):
        sum_ints(x[0])
    else: #no list so just print 
        return 0
    
    sum_ints(x[1:])
Obviously this isn't going to work. I guess what I don't understand is how to iterate through a list using recursion instead of loops. This is probably something really obvious that I'm missing.

Lurchington
Jan 2, 2003

Forums Dragoon
well, there's a couple of cheeky ways to sum lists in python:

sum(int_list)
reduce(lambda x, y: x+y, int_list)

but if you're staying on assignment, seems like this is a good way to roll it:
code:
@trace
def sum_ints(*lists):
    if len(lists)>1:
        return sum_ints(lists[0])+sum_ints(*lists[1:])
    elif lists[0]:
        return lists[0][0]+sum_ints(lists[0][1:])
    else:
        return 0
yielding output from my tracing decorator for:

print sum_ints([1,2,3])

code:
TRACE START: sum_ints([1, 2, 3])
TRACE START: sum_ints([2, 3])
TRACE START: sum_ints([3])
TRACE START: sum_ints([])
TRACE END: sum_ints([]) = 0
TRACE END: sum_ints([3]) = 3
TRACE END: sum_ints([2, 3]) = 5
TRACE END: sum_ints([1, 2, 3]) = 6
print sum_ints([1,2,3], [1,2,3])

code:
TRACE START: sum_ints([1, 2, 3], [1, 2, 3])
TRACE START: sum_ints([1, 2, 3])
TRACE START: sum_ints([2, 3])
TRACE START: sum_ints([3])
TRACE START: sum_ints([])
TRACE END: sum_ints([]) = 0
TRACE END: sum_ints([3]) = 3
TRACE END: sum_ints([2, 3]) = 5
TRACE END: sum_ints([1, 2, 3]) = 6
TRACE START: sum_ints([1, 2, 3])
TRACE START: sum_ints([2, 3])
TRACE START: sum_ints([3])
TRACE START: sum_ints([])
TRACE END: sum_ints([]) = 0
TRACE END: sum_ints([3]) = 3
TRACE END: sum_ints([2, 3]) = 5
TRACE END: sum_ints([1, 2, 3]) = 6
TRACE END: sum_ints([1, 2, 3], [1, 2, 3]) = 12
edit: just saw a stipulation of lists of lists, so rewriting

alright, I have a question:

what's the proper way to implement collections.Iterator in my object.

I defined my next() (even though collections implies you definite __next__, only next() is called) method to something like this:
code:
def next(self):

    for path in self._file_paths:
        yield self._initialize_function(path)
and if I do this:
code:

    for init_file in my_object:
        print init_file
I go infinite.

but I change next to be something like "yield_init_file" and do:

code:

    for init_file in my_object.yield_init_file():
        print init_file
it works as expected.

I've never delved deep into iterators for my own classes, so there's some subtlety I'm missing.

Lurchington fucked around with this message at 04:58 on Feb 2, 2010

Allie
Jan 17, 2004

Choose one of the following:

1. Return some other iterable object:

code:
>>> class Foo(object):
...     def __iter__(self):
...         return iter([1, 2, 3])
... 
>>> for i in Foo():
...     print i
... 
1
2
3
2. Use a generator:

code:
>>> class Foo(object):
...     def __iter__(self):
...         for i in [1, 2, 3]:
...             yield i
... 
>>> for i in Foo():
...     print i
... 
1
2
3
3. Implement iteration using the class itself:

code:
>>> class Foo(object):
...     def __init__(self):
...         self.bar = [1, 2, 3]
...         self.pos = 0
...     def __iter__(self):
...         return self
...     def next(self):
...         if self.pos >= len(self.bar):
...             self.pos = 0
...             raise StopIteration
...         i = self.bar[self.pos]
...         self.pos += 1
...         return i
... 
>>> for i in Foo():
...     print i
... 
1
2
3
I think #2 is the simplest in most cases.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

2 + 2 = 5 posted:

I'm trying to figure out how to add up all the integers in a list (or recursively all the lists it contains).

code:
>>> ints = [1,2,[3,4,[5,6],7],8,9]
>>> sum_ints = lambda x: sum(i if str(i).isdigit() else sum_ints(i) for i in x)
>>> sum_ints(ints)
45

2 + 2 = 5
Apr 11, 2003
I find it decidedly INCONVENIENT that the gun was never found.

Lurchington posted:

Bunch of helpful stuff

This is great, but it fails when the list is further nested (i.e. sum_ints([[[[3]]]]) should return "3"). This would be a snap to do using loops but they've stipulated only to use recursive function calls.

Captain Capacitor
Jan 21, 2008

The code you say?
Based on what Lurchington wrote, I adjusted it to be as such:

code:
def sum_ints(intlist):
    if not intlist:
        return 0
    elif isinstance(intlist[0], list):
        return sum_ints(intlist[0]) + sum_ints(intlist[1:])
    return intlist[0] + sum_ints(intlist[1:])


# Outputs
sum_ints([1, 2, 3])
sum_ints([2, 3])
sum_ints([3])
sum_ints([])
sum_ints([]) -> 0
sum_ints([3]) -> 3
sum_ints([2, 3]) -> 5
sum_ints([1, 2, 3]) -> 6
6
sum_ints([[[[3]]]])
sum_ints([[[3]]])
sum_ints([[3]])
sum_ints([3])
sum_ints([])
sum_ints([]) -> 0
sum_ints([3]) -> 3
sum_ints([])
sum_ints([]) -> 0
sum_ints([[3]]) -> 3
sum_ints([])
sum_ints([]) -> 0
sum_ints([[[3]]]) -> 3
sum_ints([])
sum_ints([]) -> 0
sum_ints([[[[3]]]]) -> 3
3

2 + 2 = 5
Apr 11, 2003
I find it decidedly INCONVENIENT that the gun was never found.
Awesome - thanks for the help.

Lurchington
Jan 2, 2003

Forums Dragoon

2 + 2 = 5 posted:

This is great, but it fails when the list is further nested (i.e. sum_ints([[[[3]]]]) should return "3"). This would be a snap to do using loops but they've stipulated only to use recursive function calls.

I wasn't sure based on the problem statement if it was a more lists ("it" being the arguments list) vs nested list ("it" being the 1 list argument with lists inside of it) thing. No prob.

---

Thanks Milde, I went with #2. I wish the difference between iterator and iterable was more clear at the time

Lurchington fucked around with this message at 02:57 on Feb 3, 2010

nbv4
Aug 21, 2002

by Duchess Gummybuns
code:
(env)41 16:58:38 chris@linode /srv/proj $ pip install -E env/ -e svn+http://django-
forum.googlecode.com/svn/trunk/#egg=django-forum
Checking out django-forum from svn+http://django-forum.googlecode.com/svn/trunk/#egg=django-
forum checkout from svn+http://django-forum.googlecode.com/svn/trunk/#egg=django-
forum
  Checking out http://django-forum.googlecode.com/svn/trunk/ to ./env/src/django-forum
  Error [Errno 2] No such file or directory while executing command svn checkout -q
 http://django-forum.googlecode.com/svn/trunk/ /srv/proj/env/src/django-forum
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/pip.py", line 252, in main
    self.run(options, args)
  File "/usr/lib/python2.6/dist-packages/pip.py", line 408, in run
    requirement_set.install_files(finder, force_root_egg_info=self.bundle)
  File "/usr/lib/python2.6/dist-packages/pip.py", line 1741, in install_files
    req_to_install.update_editable()
  File "/usr/lib/python2.6/dist-packages/pip.py", line 1486, in update_editable
    version_control(self.url).obtain(self.source_dir)
  File "/usr/lib/python2.6/dist-packages/pip.py", line 2563, in obtain
    ['svn', 'checkout', '-q'] + rev_options + [url, dest])
  File "/usr/lib/python2.6/dist-packages/pip.py", line 3509, in call_subprocess
    cwd=cwd, env=env)
  File "/usr/lib/python2.6/subprocess.py", line 621, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Storing complete log in ./pip-log.txt
Does anyone know what could be the problem here? The exact same code (with a different -E path) works on my local machine just fine. The above is the output from my production machine.

nbv4 fucked around with this message at 23:14 on Feb 4, 2010

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

nbv4 posted:


Does anyone know what could be the problem here? The exact same code (with a different -E path) works on my local machine just fine. The above is the output from my production machine.

Install svn / subversion on the production box.

nbv4
Aug 21, 2002

by Duchess Gummybuns

m0nk3yz posted:

Install svn / subversion on the production box.

oh snap that did it. thanks

darnzen
Jun 25, 2005

I crap dark matter.
Kind of a question about specific modules, but maybe one of you guys will have more experience than I with either of these and point me in the right direction.

I've written an app using the wck library (widget construction kit, see https://www.effbot.org), in addition to the wckGraph module. What I'd like to do, is take the output of one of my windows (happens to be a graph), and save it as a *.png or *.gif. I was planning on using the PIL for this. I'd like to use the code I have as is, without re-writing all the graphic calls to use PIL methods.

WCK uses its own "pixmap" class for storing images in memory. I can't find any documentation or class reference for pixmap and what I find in the source is confusing.

Does anyone have any direct experience with these libraries that can tell me that there's some super easy thing I'm missing? I'd love it if the wck pixmap is compatible with PIL. I don't have the time to mess with it unless I know its going to work.

One thing that's frustrating is if I was writing this in c/c++, getting a bitmap from the screen would be trivial. It may be trivial in python as well, but I just don't know how to do it!

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I'm working with the gdata-python-client code, but have hit a wall. I'm trying to change permissions on a document, but for some reason GetAclLink() returns None even though the GDataEntry contains an accessControlList:

code:
print 'new_entry: '
print new_entry
print 'type(new_entry): '
print type(new_entry)
print 'type(new_entry.GetAclLink()): '
print type(new_entry.GetAclLink())
yields (I formatted the XML a bit to make it readable)

code:
new_entry: 
<?xml version='1.0' encoding='UTF-8'?>
<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom">
	<ns0:category label="document" scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#document" />
	<ns0:category label="viewed" scheme="http://schemas.google.com/g/2005/labels" term="http://schemas.google.com/g/2005/labels#viewed" />
	<ns0:id>[url]http://docs.google.com/feeds/documents/private/full/document%3Adocid[/url]</ns0:id>
	<ns0:author>
		<ns0:name>name</ns0:name>
		<ns0:email>email@domain.com</ns0:email>
	</ns0:author>
	<ns0:content src="http://docs.google.com/feeds/download/documents/Export?docId=docid" type="text/html" />
	<ns0:updated>2010-02-05T11:36:10.831Z</ns0:updated>
	<ns0:published>2010-02-05T11:36:10.744Z</ns0:published>
	<ns0:title type="text">gdoc_test</ns0:title>
	<ns0:link href="http://docs.google.com/a/basepointmedia.com/Doc?docid=docid&amp;hl=en_US" rel="alternate" type="text/html" />
	<ns0:link href="http://docs.google.com/feeds/documents/private/full/document%3Adocid" rel="self" type="application/atom+xml" />
	<ns0:link href="http://docs.google.com/feeds/documents/private/full/document%3Adocid/g5awhwxf" rel="edit" type="application/atom+xml" />
	<ns0:link href="http://docs.google.com/feeds/media/private/full/document%3Adocid/g5awhwxf" rel="edit-media" type="text/html" />
	<ns1:resourceId xmlns:ns1="http://schemas.google.com/g/2005">document:docid</ns1:resourceId>
	<ns1:lastModifiedBy xmlns:ns1="http://schemas.google.com/g/2005">
		<ns0:name>name</ns0:name>
		<ns0:email>email@domain.com</ns0:email>
	</ns1:lastModifiedBy>
	<ns1:lastViewed xmlns:ns1="http://schemas.google.com/g/2005">2010-02-05T11:36:10.883Z</ns1:lastViewed>
<ns1:quotaBytesUsed xmlns:ns1="http://schemas.google.com/g/2005">0</ns1:quotaBytesUsed>
	<ns1:writersCanInvite value="true" xmlns:ns1="http://schemas.google.com/docs/2007" />
	<!-- HERE -->
	<ns1:feedLink href="http://docs.google.com/feeds/acl/private/full/document%3Adocid" rel="http://schemas.google.com/acl/2007#accessControlList" xmlns:ns1="http://schemas.google.com/g/2005" />
	<!-- HERE -->
</ns0:entry>
type(new_entry): 
<class 'gdata.GDataEntry'>
type(new_entry.GetAclLink()): 
<type 'NoneType'>
As far as I can tell, it ought to be matched by the gdata code (from the google code repo):

code:
  def GetAclLink(self):
    for a_link in self.link:
      if a_link.rel == 'http://schemas.google.com/acl/2007#accessControlList':
        return a_link
    return None
Any ideas?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Seems like a bug in their code maybe?

If I print out link.rel for the entry, I only get:

code:
alternate
self
edit
edit-media
Which makes sense since the ACL is a feedLink, not a link.

I'm writing an issue on their page with more details. In the meantime, this works for me:

code:
def getAclLinkhref(entry):
        if entry.GetAclLink() != None:
                return entry.GetAclLink().href
        for a_element in entry.__dict__.get('extension_elements'):
                if a_element.tag == 'feedLink' and a_element.attributes.get('rel') == 'http://schemas.google.com/acl/2007#accessControlList':
                        return a_element.attributes.get('href')

Carthag Tuek fucked around with this message at 13:30 on Feb 5, 2010

king_kilr
May 25, 2007
I wouldn't be suprised if it's a bug in their code, some parts of the gdata lib are completely out of date (the contacts part for example uses version 1 of an API that's at version 3).

nbv4
Aug 21, 2002

by Duchess Gummybuns
Anyone have any experience with numpy? I have an array of numbers that I need the outliers removed from. I'm thinking this sort of thing is right up numpy's alley. I have a dynamically generated lists of floats, where 99% of the numbers will be between 50 and 100 (for instance), but there may also be a few numbers in the 800 range. Basically I'm sending those numbers off to be plotted onto a histogram, and in some of the graphs, a single huge value makes the real data squished on the histogram. I just need some way to snip those unwanted huge values away. I'm not really a stats person, so I don't know where to look for such a function.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

nbv4 posted:

I'm not really a stats person, so I don't know where to look for such a function.

Well, the main problem is that what you're looking for isn't exactly a function (but it owns):
code:
A = numpy.array(blah)
A[A>100] = 100
A[A<50] = 50
If you want to remove the values rather than clamp them:
code:
A[(A>50) & (A<100)]

Avenging Dentist fucked around with this message at 14:43 on Feb 8, 2010

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Avenging Dentist posted:

Well, the main problem is that what you're looking for isn't exactly a function (but it owns):
code:
A = numpy.array(blah)
A[A>100] = 100
A[A<50] = 50
If you want to remove the values rather than clamp them:
code:
A[(A>50) & (A<100)]

I have no use for numpy, but I can see that that feature does own!

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

Well, the main problem is that what you're looking for isn't exactly a function (but it owns):
code:
A = numpy.array(blah)
A[A>100] = 100
A[A<50] = 50
If you want to remove the values rather than clamp them:
code:
A[(A>50) & (A<100)]

I was thinking something more automatic. Like if I had [1,2,3,4,850] it would remove 850 as it is an outlier. Whereas [850,851,855] will be untouched since theres no outliers. I guess I could always just separately calculate the correct range, then manually filter out the values outside of that range, but thats for the small statistics questions megathread I guess lmao.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Ok so strip out all elements more than a standard deviation from the mean:
code:
A[(A < A.mean()+A.std()) & (A > A.mean()-A.std())]

  • Locked thread