Skip to main content

Posts

Numpy: Accessing sub ndarrays with multiple index lists

I am trying to access (more precisely: add to) a subset of a numpy array using multiple index lists. However, what is working perfectly with slices, does not work as expected using arbitrary index lists: import numpy as np # this one works: A_4th_order = np.zeros( (4,2,4,2) ) sub_a = np.ones( (3,1,3,1) ) i = k = slice(0,3) j = l = slice(1,2) A_4th_order[i,j,k,l] += sub_a # this one doesn't: B_4th_order = np.zeros( (4,2,4,2) ) sub_b = np.ones( (3,1,3,1) ) i = k = np.array([0,1,2], dtype=int) j = l = np.array([1], dtype=int) B_4th_order[i,j,k,l] += sub_b How can I achieve this operation in an efficient and readable manner? source https://stackoverflow.com/questions/77793897/numpy-accessing-sub-ndarrays-with-multiple-index-lists

Why can't I put two while statements on top of each other?

I am fairly new to python, so this is probably a beginner mistake, but depending on how I order the while statements, it either doesn't load, or doesn't update time. import time clock = 0 Basically, when I put the while statements in this order, the code actually runs, but the second while statement never activates. while 1<2: x = inpu(input('What do you want to do?')); if x == "time": print(clock) else: print(x) while 2<4: time.sleep(5) clock += 1 When I put the while statements like this, the code just doesn't run. while 2<4: time.sleep(5) clock += 1 while 1<2: x = inpu(input('What do you want to do?')); if x == "time": print(clock) else: print(x) I didn't go into detail about inpu() , but it basically says, if you type ___ in the input, it will respond with ___. One of those options is "clock", which will print the clock value. Wh

Getting a very simple stablebaselines3 example to work

I tried to model the simplest coin flipping game where you have to predict if it is going to be a head. Sadly it won't run, given me: Using cpu device Traceback (most recent call last): File "/home/user/python/simplegame.py", line 40, in <module> model.learn(total_timesteps=10000) File "/home/user/python/mypython3.10/lib/python3.10/site-packages/stable_baselines3/ppo/ppo.py", line 315, in learn return super().learn( File "/home/user/python/mypython3.10/lib/python3.10/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 264, in learn total_timesteps, callback = self._setup_learn( File "/home/user/python/mypython3.10/lib/python3.10/site-packages/stable_baselines3/common/base_class.py", line 423, in _setup_learn self._last_obs = self.env.reset() # type: ignore[assignment] File "/home/user/python/mypython3.10/lib/python3.10/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py"

how to solve this warning in python?

enter image description here the init .py, all the file in datasets can run successfully, but why the main.py says NoModuleNamed 'coco'?, the coco.py can run successfully either. By the way , the engine.py raises the same problem as main.py i tried to change the root path of the coco data, but it doesn't work, source https://stackoverflow.com/questions/77776068/how-to-solve-this-warning-in-python

How do I correctly resume a session for a user?

I've just started learning next.js (TypeScript) and I've run into a problem. I need to authorize a user to restore his session. The authorization key is a token that is stored in cookies. How to implement this task correctly? At the moment, I have simply created a component in which I have embedded RootLayout , and in the component itself I am already executing an API request to search for a user by token, but with this approach I get various errors. Perhaps there are some other options? 'use client'; import { fetcher } from '@/helpers/fetcher'; import { useUserStore } from '@/store/user'; import { QueryCache, useQuery } from '@tanstack/react-query'; import { deleteCookie, getCookie } from 'cookies-next'; import { useEffect } from 'react'; export default function Auth() { const { user, setUser } = useUserStore(); const rememberToken = getCookie('remember_token'); if (user == null && rememberToken !=

Encode audio data to string (Flask) and decode it (Javascript)

I have a Python Flask app with the method shown below. In the method I'm synthesizing voice from text using Azure text to speech. @app.route("/retrieve_speech", methods=['POST']) def retrieve_speech(): text= request.form.get('text') start = time.time() speech_key = "my key" speech_region = "my region" speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=speech_region) speech_config.endpoint_id = "my endpoint" speech_config.speech_synthesis_voice_name = "voice name" speech_config.set_speech_synthesis_output_format( speechsdk.SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3) synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=None) result = synthesizer.speak_text_async(text=text).get() if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted: # Convert to wav audio = AudioSegment

Recommend extraction api/library for better extracting all information in a pdf using Nodejs [closed]

What library or API is the best at extracting information in a PDF file in Nodejs. Things like text (how they properly are structured), images (couple with information on images like text if it got one), table etc... I'm aware of libraries like pdf-extract and the rest but most of them capabilities are limited to just extracting text and pretty much can't do other stuffs I mentioned above. Also, I don't want to mix many different libraries to do the tricks. So what do you suggest? Via Active questions tagged javascript - Stack Overflow https://ift.tt/aTZwn7q