python-3.x

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

久未见 提交于 2021-02-11 13:27:18
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

Replacing for loops with function call inside with broadcasting/vectorized solution

a 夏天 提交于 2021-02-11 13:26:41
问题 Problem: When using broadcasting, rather than broadcasting scalars to match the arrays, the vectorized function is instead, for some reason, shrinking the arrays to scalars. MWE: Below is a MWE. It contains a double for loop. I am having trouble writing faster code that does not use the for loops, but instead, uses broadcasting/vectorized numpy. import numpy as np def OneD(x, y, z): ret = np.exp(x)**(y+1) / (z+1) return ret def ThreeD(a,b,c): value = OneD(a[0],b[0], c) value *= OneD(a[1],b[1]

Replacing for loops with function call inside with broadcasting/vectorized solution

不羁的心 提交于 2021-02-11 13:26:09
问题 Problem: When using broadcasting, rather than broadcasting scalars to match the arrays, the vectorized function is instead, for some reason, shrinking the arrays to scalars. MWE: Below is a MWE. It contains a double for loop. I am having trouble writing faster code that does not use the for loops, but instead, uses broadcasting/vectorized numpy. import numpy as np def OneD(x, y, z): ret = np.exp(x)**(y+1) / (z+1) return ret def ThreeD(a,b,c): value = OneD(a[0],b[0], c) value *= OneD(a[1],b[1]

SPACY custom NER is not returning any entity

主宰稳场 提交于 2021-02-11 13:24:58
问题 I am trying to train a Spacy model to recognize a few custom NERs, the training data is given below, it is mostly related to recognizing a few server models, date in the FY format and Types of HDD: TRAIN_DATA = [('Send me the number of units shipped in FY21 for A566TY server', {'entities': [(39, 42, 'DateParse'),(48,53,'server')]}), ('Send me the number of units shipped in FY-21 for A5890Y server', {'entities': [(39, 43, 'DateParse'),(49,53,'server')]}), ('How many systems sold with 3.5 inch

How to convert a string to a user discord.py

可紊 提交于 2021-02-11 13:23:33
问题 I'm trying to convert a string to a user so I can dm them. Here's my current code: @bot.command(pass_context=True) async def partnerwarn(ctx): file_names = glob.glob("p*") for file in file_names: f = open(file, 'r') content = f.read() f.close() member = file[1:] await bot.send_message(member : discord.User, "You've had under 7 partners! This is a warning, please make sure you actively partner!") print("Warned!") await bot.reply("**" + file[1:] + " was warned!**") It doesn't work because

How to decode unicode string that is read from a file in Python?

烈酒焚心 提交于 2021-02-11 13:22:31
问题 I have a file containing UTF-16 strings. When I try to read the unicode, " " (double quotes) are added and the string looks like "b'\\xff\\xfeA\\x00'" . The inbuilt .decode function throws a AttributeError: 'str' object has no attribute 'decode' . I tried a few options but those didn't work. This is what the file I am reading from looks like 回答1: Try this: str.encode().decode() 回答2: It looks like the file has been created by writing bytes literals to it, something like this: some_bytes = b

How to decode unicode string that is read from a file in Python?

…衆ロ難τιáo~ 提交于 2021-02-11 13:21:35
问题 I have a file containing UTF-16 strings. When I try to read the unicode, " " (double quotes) are added and the string looks like "b'\\xff\\xfeA\\x00'" . The inbuilt .decode function throws a AttributeError: 'str' object has no attribute 'decode' . I tried a few options but those didn't work. This is what the file I am reading from looks like 回答1: Try this: str.encode().decode() 回答2: It looks like the file has been created by writing bytes literals to it, something like this: some_bytes = b

Recursion optimization

拈花ヽ惹草 提交于 2021-02-11 13:18:18
问题 I'm trying to find a certain path through my 2d array My array could look like this: temp = [ ["placeholder", 2, 0], ["placeholder", 1, 7, 3], ["placeholder", 4, 5, 8], ["placeholder", 6, 3, 5, 2], ["placeholder", 7], ["placeholder", 3, 0], ] The inner arrays contain a placeholder followed by a variable amount of integers. These integers range in value between 0-19 (0 and 19 both included) I wanna find a path from top to bottom through these inner arrays where no number is used more than once

Sort json list from another list

限于喜欢 提交于 2021-02-11 13:14:12
问题 I'm trying to sort a json list from another list. example: jsonList = [{'id': 'das', 'name': 'something'}, {'id': 'rtn', 'name': 'Something Else'}, {'id': 'ddsn', 'name': 'Something ElseElse'}] orderList = ['rtn', 'ddsn', 'das'] goodList = someFunction(jsonList, orderList ) I need the output to be the json list sorted by the id: goodList = [{'id': 'rtn', 'name': 'Something Else'}, {'id': 'ddsn', 'name': 'Something ElseElse'}, {'id': 'das', 'name': 'something'}] 回答1: goodList = sorted(jsonList

Can not run .exe packed by pyinstaller

老子叫甜甜 提交于 2021-02-11 13:12:58
问题 My source code I am using pyfiglet in my project and when compiling the .exe it returns Traceback (most recent call last): File "pkg_resources\__init__.py", line 358, in get_provider KeyError: 'pyfiglet.fonts' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "Dragon_Game.py", line 5, in <module> File "pyfiglet\__init__.py", line 65, in figlet_format File "pyfiglet\__init__.py", line 820, in __init__ File "pyfiglet\__init__.py", line