python-2.7

Non-commutative sympify (or simplify)

情到浓时终转凉″ 提交于 2021-02-06 09:28:09
问题 I would like to be able to simplify mathematical expressions from a string in Python. There are several "commutative" ways of doing it. Is there a non-commutative function for that? I know that sympify from sympy can do some non-commutative jobs, here you have an example: from sympy import * x=Symbol('x',commutative=False) y=Symbol('y',commutative=False) print sympify(3*x*y - y*x - 2*x*y) it will print x y -y x, however if we apply sympify to the string, that is, print sympify('3*x*y - y*x -

Finding polynomial roots using Python — Possible Numpy Extension Bug

隐身守侯 提交于 2021-02-06 09:05:01
问题 I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'. My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3 . (Simple) But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?) Could anyone please find the culprit in my code? Or is it simply a bug? from numpy.polynomial import Polynomial as P p = P([1, 5, 6]) p.roots() 回答1: Simply pass it in the other order, p = P([6, 5, 1]) 回答2: You could have realized this yourself if you had

Finding polynomial roots using Python — Possible Numpy Extension Bug

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-06 09:04:49
问题 I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'. My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3 . (Simple) But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?) Could anyone please find the culprit in my code? Or is it simply a bug? from numpy.polynomial import Polynomial as P p = P([1, 5, 6]) p.roots() 回答1: Simply pass it in the other order, p = P([6, 5, 1]) 回答2: You could have realized this yourself if you had

StereoCalibration in OpenCV on Python

ⅰ亾dé卋堺 提交于 2021-02-06 06:35:41
问题 I am new in OpenCV, and could not find normal tutorial for stereoCalibration on Python. If you have some samples, please share. I do single calibration for each of cameras, and i have next problem. The left one: The right one: PS: I'm doing Depth-map and by the metter of it, i received bad map. UPDATE: I have ported the C++ version from https://github.com/jayrambhia/Vision/blob/master/OpenCV/C%2B%2B/stereocalibrate.cpp Yeah, it has no error but it return only fully black images Ported cod:

StereoCalibration in OpenCV on Python

断了今生、忘了曾经 提交于 2021-02-06 06:30:56
问题 I am new in OpenCV, and could not find normal tutorial for stereoCalibration on Python. If you have some samples, please share. I do single calibration for each of cameras, and i have next problem. The left one: The right one: PS: I'm doing Depth-map and by the metter of it, i received bad map. UPDATE: I have ported the C++ version from https://github.com/jayrambhia/Vision/blob/master/OpenCV/C%2B%2B/stereocalibrate.cpp Yeah, it has no error but it return only fully black images Ported cod:

StereoCalibration in OpenCV on Python

江枫思渺然 提交于 2021-02-06 06:30:50
问题 I am new in OpenCV, and could not find normal tutorial for stereoCalibration on Python. If you have some samples, please share. I do single calibration for each of cameras, and i have next problem. The left one: The right one: PS: I'm doing Depth-map and by the metter of it, i received bad map. UPDATE: I have ported the C++ version from https://github.com/jayrambhia/Vision/blob/master/OpenCV/C%2B%2B/stereocalibrate.cpp Yeah, it has no error but it return only fully black images Ported cod:

Remove all hex characters from string in Python

感情迁移 提交于 2021-02-06 03:01:50
问题 Although there are similar questions, I can't seem to find a working solution for my case: I'm encountering some annoying hex chars in strings, e.g. '\xe2\x80\x9chttp://www.google.com\xe2\x80\x9d blah blah#%#@$^blah' What I need is to remove these hex \xHH characters, and them alone, in order to get the following result: 'http://www.google.com blah blah#%#@$^blah' decoding doesn't help: s.decode('utf8') # u'\u201chttp://www.google.com\u201d blah blah#%#@$^blah' How can I achieve that? 回答1:

Remove all hex characters from string in Python

早过忘川 提交于 2021-02-06 03:01:28
问题 Although there are similar questions, I can't seem to find a working solution for my case: I'm encountering some annoying hex chars in strings, e.g. '\xe2\x80\x9chttp://www.google.com\xe2\x80\x9d blah blah#%#@$^blah' What I need is to remove these hex \xHH characters, and them alone, in order to get the following result: 'http://www.google.com blah blah#%#@$^blah' decoding doesn't help: s.decode('utf8') # u'\u201chttp://www.google.com\u201d blah blah#%#@$^blah' How can I achieve that? 回答1:

Using pandas to read text file with leading whitespace gives a NaN column

我们两清 提交于 2021-02-05 20:35:46
问题 I am using pandas.read_csv to read a whitespace delimited file. The file has a variable number of whitespace characters in front of every line (the numbers are right-aligned). When I read this file, it creates a column of NaN. Why does this happen, and what is the best way to prevent it? Example: Text file: 9.0 3.3 4.0 32.3 44.3 5.1 7.2 1.1 0.9 Command: import pandas as pd pd.read_csv("test.txt",delim_whitespace=True,header=None) Output: 0 1 2 3 0 NaN 9.0 3.3 4.0 1 NaN 32.3 44.3 5.1 2 NaN 7.2

Using pandas to read text file with leading whitespace gives a NaN column

ⅰ亾dé卋堺 提交于 2021-02-05 20:35:23
问题 I am using pandas.read_csv to read a whitespace delimited file. The file has a variable number of whitespace characters in front of every line (the numbers are right-aligned). When I read this file, it creates a column of NaN. Why does this happen, and what is the best way to prevent it? Example: Text file: 9.0 3.3 4.0 32.3 44.3 5.1 7.2 1.1 0.9 Command: import pandas as pd pd.read_csv("test.txt",delim_whitespace=True,header=None) Output: 0 1 2 3 0 NaN 9.0 3.3 4.0 1 NaN 32.3 44.3 5.1 2 NaN 7.2