2018-10-22         Bowen

vectorized interpolation on array with nans

I am trying to interpolate an image cube NDIM=(dim_frequ, dim_spaxel1, dim_spaxel1) along the frequency axis. The aim is to oversample the frequency space. The array may contain nans. It would, of course, be possible to run two for loops over the array but that's definitely too slow. What I want in pseudo code:import numpy as npfrom scipy.interpolate import interp1ddim_frequ, dim_spaxel1, dim_spaxel2 = 2559, 70, 70cube = np.random.rand(dim_frequ, dim_spaxel1, dim_spaxel2)cube.ravel()[np.random.choice(cube.size, 1000, replace=False)] = np.nan wavelength = np.arange(1...

 python                     1 answers                     26 view
 2018-10-22         Tiffany

How to obtain statistic from chisquare

For example when you enterfrom scipy.stats import chisquarechisquare(f_obs=[175,25,125,125],f_exp=[133.3,66.7,166.7,83.3])This returnsPower_divergenceResult(statistic=70.42153483789218, pvalue=3.4673013490296832e-15)How do I get just the statistic (i.e. 70.42153483789218)? Simply add .statistic to access that attribute:>>> chisquare(f_obs=[175,25,125,125],f_exp=[133.3,66.7,166.7,83.3]).statistic70.42153483789218Likewise, you can access pvalue in the same way:>>> chisquare(f_obs=[175,25,125,125],f_exp=[133.3,66.7,166.7,83.3]).pvalue3.4673013490296832e-15...

 python                     2 answers                     26 view
 2018-10-22         Claire

What is the Python interpolate function which is the same as spapi in Matlab

In Matlab, I can use the spline interpolation function spapi to generate a spline curve, so that prescribed values of the curves and its first two derivatives can be matched. For example:spapi([0 0 0 0 1 2 2 2 2],[0 1 1 1 2],[2 0 1 2 -1])this produces the unique cubic spline f on the interval [0..2] with exactly one interior knot, at 1, that satisfies the five conditions f(0)=2, f(1)=0, f'(1)=1, f''(1)=2, f(2)=–1These include 3-fold matching at 1, i.e., matching there to prescribed values of the function and its first two derivatives.In Python, however, the spline interpol...

 python                     1 answers                     31 view
 2018-10-22         Michelle

Unable to terminate a python program

As suggested over here, I have created a separate class, exclusively for Tkinter. The main function just gets the scale values from the Tkinter GUI. Though I'm able to get these scale values, I am unable to exit the program after closing the GUI. My program just seems to be stuck after self.root.mainloop() i.e print "mainloop" gets executed. I do not have any problems in terminating the script, if I do something as follows, i.e, if I do not access the output_q values i = 0while app.run: print i i = i+1The entire code is given belowfrom Tkinter import *import threading, time...

 python                     1 answers                     37 view
 2018-10-22         Dana

Tcl_AsyncDelete Error. Unable to terminate Tk

I am using Tkinter in a ROS node to create a GUI and publish the scale values to another ROS Node. I have accomplished this. The problem comes when I try to close this GUI and rerun the node. The log message that I get is as follows: Exception RuntimeError: 'main thread is not in main loop' in <bound method DoubleVar.__del__ of <Tkinter.DoubleVar instance at 0x7f19ea0c3ab8>> ignoredTcl_AsyncDelete: async handler deleted by the wrong threadAborted (core dumped)According to this, I think I will have to terminate Tk from its own thread. But I do not know how to do ...

 python                     1 answers                     46 view
 2018-10-22         Penelope

Python: How to make Pillow and Tkinter compatible?

I'm trying to run some Python code that uses both tkinter and Pillow. When I run the code in my IDE (Pycharm), the program opens and there are no issues. However, when I try to the run the code on its own as a Python file, I get a quick flash of the Command prompt which immediately shuts down. Im running Python 3.7.0 (latest version), which means I also have the latest version of tkinter, as well as Pillow 5.2.0. How do I get my code to run with its UI as a standalone python file?from tkinter import *from PIL import Image, ImageTkroot = Tk()mapFrame=Frame(root)mapFrame.plac...

 python                     1 answers                     50 view
 2018-10-22         Pamela

Cloning tkinter Buttons with other function

right now I am working on a python phone book with following layout:|Name | Surname | Now I want to create a button for each contacts Name and Surname, so 2 buttons for 1 contact * n. If I press on the Name or Surname a box with more details of the contact should open.Can anyone please help me?I tried following so far:prename = ["John", "Jack"]surname = ["Tompson", "Daniels"]x = 0y = 0for pn in prename: pre = Button(main, text=pn) pre.grid(row=x, column=0) x += 1for sn in surname: sur = Button(main, text=sn) sur.grid(row=y, column=1) y += 1 You need to ...

 python                     1 answers                     53 view
 2018-10-22         Lauren

pymongo : How can I get multiple results from filed in mongodb?

I would like to get every 'ecg_raw' in 'data' itmes that founded by 'name' with python3 pymongo.If i know 'name' and 'time_info', How can i get 4 ecg_raw datas which time_info == '2018-09-01 00:00:03'I want to get every ecg_raw data like [[8,2],[1,10],[9,4],[1,9]]I tried db.g.find({"data":{"$elemMatch":{"time_info":"2018-09-01 00:00:03"}}},{"name":1,"data":{"$elemMatch":{"time_info":"2018-09-01 00:00:03"}}})but it returns only one value like bottom.{'_id': ObjectId('5b90d401219e9c9f72cac8c4'), 'name': 'testDog3', 'data': [{'time_info': '2018-09-01 00:00:03', 'ecg_raw': [8, ...

 python                     1 answers                     85 view
 2018-10-22         Florence

Nested list from list using list comprehension?

I have the following list called flat:flat= ['11','13', '17', '19', '13', '17', '19','22','35','14','15']I splitted it into a list of tuples using zip function aslist(zip(flat[0::2], flat[1::2]))with the following output:[('11', '13'), ('17', '19'), ('13', '17'), ('19', '22'), ('35', '14')]Now, how to convert the list flat into the following result using list comprehension?[['11', '13'], ['17', '19'], ['13', '17'], ['19', '22'], ['35', '14']] Method 1: Without list ComprehensionYou need to map zip object to list:list(map(list,zip(flat[0::2], flat[1::2])))[['11', '13'], [...

 python                     4 answers                     3 view
 2018-10-22         Pete

How to make unique lists across Python class objects?

I am trying to make a python class that keeps a list of uniformly distributed random numbers per class but the numbers must be unique to that class. However the list in each new object is copied exactly as is from the first object and if I manually append new values to the contents of the second objects list, the same change is applied to the first object's list and for every new class I create the list is again copied and it appends however many values I specified.The code is as follows:import random as randomclass myClass: myRandomList = [] def __init__(self, length...

 python                     3 answers                     7 view
 2018-10-22         Basil

List index out of range, but the item exists

I get this error and I don't understand why. List index out of range, but the item exists.1 [u'http://(ip1):(port1)', u'http://(ip2):(port2)']Exception in thread Thread-11:Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "(path).py", line 57, in match_fetcher self.fetch_match(match) File "(path).py", line 65, in fetch_match response = self.http_get(url) File "(path).py", line 75, in ht...

 python                     1 answers                     11 view
 2018-10-22         Darnell

Algorithm of searching for a pair of integers in a list

I'm quite new to algorithm and I encountered a question to which my approach does not works properly. Here's the precondition:You are given a list L=[(a1,b1),…,(an,bn)] of n pairs of integers. For any two pairs (ai,bi)∈L and (aj,bj)∈L such that 1≤i≤j≤n , we have (at least) one of three cases:ai=aj and bi=bj ai < aj bi < bj For example, the list L=[(1,2),(1,1)] would not be valid. An example of a valid list is: L = [(0,1), (1, 0), (0, 1), (1, 1), (1, 2), (3, 1), (3, 1), (2, 2), (2, 3), (3, 2), (2, 3), (4, 3), (3, 4), (4, 4), (4, 5), (5, 5)]The question is: Write ...

 python                     1 answers                     11 view
 2018-10-22         Jerry

Remove the outer list from dictionary values

I want to remove the outer list from dictionary values but I can only find the unpacking method not sure how to use this on dictionary values.My data look like thisDIC{'A': array([[ 1.90769404e-01, 1.26112014e-01, -2.17013955e-02]],'B': array([[ 2.80194253e-01, 1.19333006e-01, 3.63824964e-02]],'C': array([[ 1.40285566e-01, 4.76801395e-02, 5.49828596e-02]]}I want to remove the outer list to make them like this{'A': array([ 1.90769404e-01, 1.26112014e-01, -2.17013955e-02],'B': array([ 2.80194253e-01, 1.19333006e-01, 3.63824964e-02],'C': array([ 1.40285566e-01, 4.7680...

 python                     2 answers                     12 view
 2018-10-22         Blithe

list instead of list of list

I have this code that returns a list of list, I would like to return only one list efficiently, how can I achieve that?def GetCast(path,key,Ids): list=[] for n in Ids: l=requests.get(path + str(n) + '/credits',key ) data= l.json() cast_Ids= [i['name'] for i in data['cast']] list.append(cast_Ids) return list just changelist.append(cast_Ids)bylist.extend(cast_Ids) # variant: list += cast_Ids(and don't use list from now on as it's the builtin name for the list type)or in one line with flattening list comprehension (I haven't tested this...

 python                     1 answers                     11 view
 2018-10-22         Merlin

How to set self argument into decorator?

Can someone help me?I have something like:class MyClass: def __init__(self, *, arg1, arg2): self.arg1 = arg1 self.arg2 = arg2 @test_dec('some param', self.arg2) def test_func(): passBut it doesn't work.So, how can I put self.arg2 to test_dec?I want to do something like:import socketiosio = socketio.AsyncServer()class MyClass: def __init__(self, options): self.options = options @sio.on('connect', namespace=self.options['namespace']) def func(): pass At first when there is nothing, there is no self. if you want to do it you...

 python                     2 answers                     14 view
 2018-10-22         Bernie

These two codes should do exactly the same thing, but the first one doesn't work as I expect

PythonPlease explain why these two codes work differently..Actually I am trying to make kind of AI where in initial generations the individuals will go in random directions. For keeping the code simple I have provided some random directions in Brain myself.There is an Individual class that gives a brain to the individual. It also has a function that returns a child with EXACTLY the same brain (means same directions to go in) as the parent.I have two codes:First: When some directions is changed in the parent, the same thing is changed in the child too (or if changed in child...

 python                     2 answers                     16 view

Page 2 of 10095  |  Show More Pages:  Top Prev Next Last