numpy

Display more than 16 digits in numpy [duplicate]

时光毁灭记忆、已成空白 提交于 2021-02-11 09:57:08
问题 This question already has answers here : How to pretty-print a numpy.array without scientific notation and with given precision? (14 answers) Closed last year . I tried to set np.set_printoptions(precision=100) in python but the output is still something like -0.00510610862213 Is there anyway to display e.g. 100 digits? 回答1: You can change the display precision up to a point. For example, looking below we can change the number of digits displayed up to a point after which no more digits are

How to get the types of numpy function arguments (from docstrings) using jedi in python

◇◆丶佛笑我妖孽 提交于 2021-02-11 09:40:58
问题 Ideally I would like a function which works as follows (for all kinds of numpy functions): parameter_types('np.random.binomial') and returns: {'a: 'int', 'b':'float', 'size':'int'} I understand that jedi has some support for extracting this information from docstrings, but I cannot make it work. Is it possible to get something like this using jedi? 回答1: As found in this answer, your best bet is to install numpydoc and its requirements. import numpydoc import numpy as np doc = numpydoc

How to get the types of numpy function arguments (from docstrings) using jedi in python

≯℡__Kan透↙ 提交于 2021-02-11 09:39:13
问题 Ideally I would like a function which works as follows (for all kinds of numpy functions): parameter_types('np.random.binomial') and returns: {'a: 'int', 'b':'float', 'size':'int'} I understand that jedi has some support for extracting this information from docstrings, but I cannot make it work. Is it possible to get something like this using jedi? 回答1: As found in this answer, your best bet is to install numpydoc and its requirements. import numpydoc import numpy as np doc = numpydoc

efficient way of constructing a matrix of pair-wise distances between many vectors?

限于喜欢 提交于 2021-02-11 08:10:37
问题 First, thanks for reading and taking the time to respond. Second, the question: I have a PxN matrix X where P is in the order of 10^6 and N is in the order of 10^3. So, X is relatively large and is not sparse. Let's say each row of X is an N-dimensional sample. I want to construct a PxP matrix of pairwise distances between these P samples. Let's also say I am interested in Hellinger distances. So far I am relying on sparse dok matrices: def hellinger_distance(X): P = X.shape[0] H1 = sp.sparse

OpenCV 2.4 estimateAffine3D in Python

↘锁芯ラ 提交于 2021-02-11 07:40:04
问题 I'm trying to use the method cv2.estimateAffine3D but without success. Here is my code sample : import numpy as np import cv2 shape = (1, 4, 3) source = np.zeros(shape, np.float32) # [x, y, z] source[0][0] = [857, 120, 854] source[0][1] = [254, 120, 855] source[0][2] = [256, 120, 255] source[0][3] = [858, 120, 255] target = source * 10 retval, M, inliers = cv2.estimateAffine3D(source, target) When I try to run this sample, I obtain the same error as this other post here. I'm using OpenCV 2.4

OpenCV 2.4 estimateAffine3D in Python

自作多情 提交于 2021-02-11 07:39:40
问题 I'm trying to use the method cv2.estimateAffine3D but without success. Here is my code sample : import numpy as np import cv2 shape = (1, 4, 3) source = np.zeros(shape, np.float32) # [x, y, z] source[0][0] = [857, 120, 854] source[0][1] = [254, 120, 855] source[0][2] = [256, 120, 255] source[0][3] = [858, 120, 255] target = source * 10 retval, M, inliers = cv2.estimateAffine3D(source, target) When I try to run this sample, I obtain the same error as this other post here. I'm using OpenCV 2.4

Error bars in matplotlib display over other curves

时光总嘲笑我的痴心妄想 提交于 2021-02-11 06:52:27
问题 I have a plot in which some data is represented by a scatter plot with error bars and I want to fit a curve to it. However, no matter where in the code I plot the curve, the error bars float on top of it. I want the fitted curves to display in front of the error bars because otherwise I can't see it. Here is a simple example of the issue: import numpy as np import matplotlib.pyplot as plt import matplotlib x = np.arange(1,10) r = np.random.random(x.size) fig1, ax = plt.subplots() ln1 = ax

Error bars in matplotlib display over other curves

大城市里の小女人 提交于 2021-02-11 06:52:06
问题 I have a plot in which some data is represented by a scatter plot with error bars and I want to fit a curve to it. However, no matter where in the code I plot the curve, the error bars float on top of it. I want the fitted curves to display in front of the error bars because otherwise I can't see it. Here is a simple example of the issue: import numpy as np import matplotlib.pyplot as plt import matplotlib x = np.arange(1,10) r = np.random.random(x.size) fig1, ax = plt.subplots() ln1 = ax

How to get a subset of rows from a NumPy Matrix based on a condition?

夙愿已清 提交于 2021-02-11 06:35:33
问题 How to return a set of rows of a NumPy Matrix that would match a given condition? This is a Numpy Matrix object >>> X matrix([['sunny', 'hot', 'high', 'FALSE'], ['sunny', 'hot', 'high', 'TRUE'], ['overcast', 'hot', 'high', 'FALSE'], ['rainy', 'mild', 'high', 'FALSE'], ['rainy', 'cool', 'normal', 'FALSE'], ['rainy', 'cool', 'normal', 'TRUE'], ['overcast', 'cool', 'normal', 'TRUE'], ['sunny', 'mild', 'high', 'FALSE'], ['sunny', 'cool', 'normal', 'FALSE'], ['rainy', 'mild', 'normal', 'FALSE'], [

Broadcasting/Vectorizing inner and outer for loops in python/NumPy

允我心安 提交于 2021-02-11 06:30:32
问题 Purpose I have turned a double for loop into a single for loop using vectorization . I would like to now get rid of the last loop . I want to slice an Nx3 array of coordinates and calculate distances between the sliced portion and the remaining portion without using a for loop . Two cases (1) the slice is always 3x3 . (2) the slice is variable i.e., Mx3 where M is always significantly smaller than N Vectorizing the interaction of 1 row of the slice interacting with the remainder is