Skip to main content

Posts

Python fmin - TypeError: float() argument must be a string or a number, not 'tuple' ValueError: setting an array element with a sequence

I am trying to minimize my likelihood function with the par parameter only, the rest: n,T,r,log_x, gft_y are supposed to be fixed in the optimization. When I put them in the args to fix them I get back the following errors: TypeError: float() argument must be a string or a number, not 'tuple' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\phelg\AppData\Local\Temp/ipykernel_16344/2785678381.py", line 4, in <module> result = fmin(mrg_lik,initial_guess, args) File "C:\Users\phelg\anaconda3\envs\Financial_Econometrics\lib\site-packages\scipy\optimize\optimize.py", line 580, in fmin res = _minimize_neldermead(func, x0, args, callback=callback, **opts) File "C:\Users\phelg\anaconda3\envs\Financial_Econometrics\lib\site-packages\scipy\optimize\optimize.py", line 750, in _minimize_neldermead fsim[k] = func(sim[k]) ValueError: setting an array element w...

How to access non_public_metrics field in twitter API?

I'm trying to retrieve the information within the non_public_metrics field in twitter API (i.e, "impression_count", "url_link_clicks", "user_profile_clicks"). I was able to access the public_metrics field using only the Bearer Token. But, when I include the non_public_metrics in my query params I got the error Field Authorization Error . Here is my code: import requests import collections import os from dotenv import load_dotenv load_dotenv() def auth(): return os.getenv('TWITTER_TOKEN') def create_headers(bearer_token): headers = {"Authorization": "Bearer {}".format(bearer_token)} return headers def create_url(keyword, start_date, end_date, max_results = 10): ttid = 1184334528837574656 search_url = f"https://api.twitter.com/2/users/{ttid}/tweets" #Change to the endpoint you want to collect data from #change params based on the endpoint you are using query_params = {'start_...

Are there ongoing projects to make Python greener? [closed]

I recently found this paper which analyses energy consumption of various programming languages. I mainly use python for my everyday coding, and I wonder if there are any ongoing projects to make Python be greener (and maybe also faster). I don't even know if this is possible for an interpreted language. I googled around a bit but I could not find any information. Thank you! source https://stackoverflow.com/questions/71563657/are-there-ongoing-projects-to-make-python-greener

Can't access or print any request data with fastapi

I have a simple fastapi endpoint where I want to receive a string value. In this case I tried it with a json body, but basically it doesn't need to be json. I really need only a simple string to separate the requests from each other. Unfortunately I can't access any of the request parameters with a GET method. I also tried POST method instead, but I get an error: request: url = "http://127.0.0.1:5000/ping/" payload=json.dumps({"key":"test"}) headers = { "Content-Type": "application/json" } response = requests.request("POST", url, headers=headers, json=payload) print(response.text) api: @app.get("/ping/{key}") async def get_trigger(key: Request): key = key.json() test = json.loads(key) print(test) test2 = await key.json() print(key) print(test2) return I can't print anything with post or put: @app.post("/ping/{key}") async def get_trigger(key: ...

Update a field of an associate table using the magic method of Sequelize/Node js

I have i table called Orders and another table called Cupons, this tables has a association many to one, Ordes has many cupons, and cupons belongs to order, i need to update the status of my cupom when i associate the cupons to a order, i tried this way but doesn't work await item.addCupons(cupom.id, { // the item is the order created through: { afiliado_id: afiliadoId, // and update the afiliado id status: 'validado' // update de status of cupon to 'validado' } }) ```` Via Active questions tagged javascript - Stack Overflow https://ift.tt/Spcd8nH

Why does this lambda function work for sorting by 'x' but not 'd'?

I'm having trouble understanding sorting by key using lambda function. l = ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] print('Unsorted:%s' % l) lSorted = sorted(l) print('Sorted:%s' % lSorted) lFinalSort = sorted(lSorted, key=lambda a : 'x' != a[0]) print('Final Sort:%s' % lFinalSort) lFinalSort = sorted(lSorted, Is the list we're sorting. key= is the special 'contingency' we're sorting by. lambda a : is a temporary function with a being an arbitrary argument. 'x' != a[0] This is the part that doesn't make sense on how it prioritizes sorting by 'x' first. If 'x' does not equal the first letter in the item we're sorting, sort by it? In that case, why doesn't: lFinalSort = sorted(lSorted, key=lambda a : 'd' in a) sort by all words that contain 'd' first? And why does: lFinalSort = sorted(lSorted, key=lambda a : 'd' in a...