numpy

Strange PIL.Image.fromarray behaviour with numpy zeros and ones in mode='1'

给你一囗甜甜゛ 提交于 2021-02-10 12:20:31
问题 There should be some kinda puzzle for me. Accordingly to PIL documentation it has different image modes (as 1, L, 8, RGB, RGBA, and so on), but I was interested about mode '1' (1-bit pixels, black and white, stored with one pixel per byte). I've created 2 matrices size 100 by 100: first only zeroes (np.zeros) and second only ones (np.ones), expecting totally black image with ones, and white image with zeros in mode '1' for Black and White image only. Picture of result Question: what I'm doing

C++ to numpy and back to C++, tuple PyObject

南笙酒味 提交于 2021-02-10 12:12:33
问题 I am implementing a Visual C++ code (MS VStudio 2013) that acquires an image from a camera, processes the image, sends pre-processed data (an array 2 or more doubles) to python through a PyObject, and gets numpy-processed results back from python (a tuple of 3 doubles in py, which is becomes an array of 3 doubles in C++). I tested the py function as a standalone script. However, I keep getting a null as a return from PyObject_CallObject(). python and the VC++ project reside in the same

C++ to numpy and back to C++, tuple PyObject

夙愿已清 提交于 2021-02-10 12:12:27
问题 I am implementing a Visual C++ code (MS VStudio 2013) that acquires an image from a camera, processes the image, sends pre-processed data (an array 2 or more doubles) to python through a PyObject, and gets numpy-processed results back from python (a tuple of 3 doubles in py, which is becomes an array of 3 doubles in C++). I tested the py function as a standalone script. However, I keep getting a null as a return from PyObject_CallObject(). python and the VC++ project reside in the same

C++ to numpy and back to C++, tuple PyObject

走远了吗. 提交于 2021-02-10 12:11:00
问题 I am implementing a Visual C++ code (MS VStudio 2013) that acquires an image from a camera, processes the image, sends pre-processed data (an array 2 or more doubles) to python through a PyObject, and gets numpy-processed results back from python (a tuple of 3 doubles in py, which is becomes an array of 3 doubles in C++). I tested the py function as a standalone script. However, I keep getting a null as a return from PyObject_CallObject(). python and the VC++ project reside in the same

python- convolution with step response

只谈情不闲聊 提交于 2021-02-10 10:54:45
问题 I want to compute this integral $\frac{1}{L}\int_{-\infty}^{t}H(t^{'})\exp(-\frac{R}{L}(t-t^{'}))dt^{'}$ using numpy.convolution, where $H(t)$ is heavside function. I am supposed to get this equals to $\exp(-\frac{R}{L}t)H(t)$ below is what I did, I changed the limitation of the integral into -inf to +inf by change of variable multiplying a different H(t) then I used this as my function to convolve with H(t)(the one inside the integral), but the output plot is definitely not a exp function,

Numpy : ValueError: object of too small depth for desired array

不羁岁月 提交于 2021-02-10 09:33:41
问题 I am trying to convert a MATLAB code to Python where I am stuck of how to import this line to Python: YDFA_xa_p = interp1(data(:,1),data(:,2),YDFA_lam_p*1e9,'linear')*1e-24; Now for Python I have changed it as: YDFA_xa_p = numpy.interp(data[:, 1], data[:, 2], YDFA_lam_p * 1e9) * 1e-24 data[:,1] and data[:,2] and YDFA_lam_p values are: [ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.] [ 3. 3. 3. 3. 3. 3. 3. 3. 3. 3.] 915.0 The issue I see is that the variable YDFA_lam_p is a float variable while it is

Numpy : ValueError: object of too small depth for desired array

房东的猫 提交于 2021-02-10 09:30:50
问题 I am trying to convert a MATLAB code to Python where I am stuck of how to import this line to Python: YDFA_xa_p = interp1(data(:,1),data(:,2),YDFA_lam_p*1e9,'linear')*1e-24; Now for Python I have changed it as: YDFA_xa_p = numpy.interp(data[:, 1], data[:, 2], YDFA_lam_p * 1e9) * 1e-24 data[:,1] and data[:,2] and YDFA_lam_p values are: [ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.] [ 3. 3. 3. 3. 3. 3. 3. 3. 3. 3.] 915.0 The issue I see is that the variable YDFA_lam_p is a float variable while it is

Checking if a point is in ConvexHull?

天大地大妈咪最大 提交于 2021-02-10 08:44:58
问题 I am having trouble understanding how to compute whether an n-dimensional point is within an n-dimensional ConvexHull. A very similar question (the same) was asked here: What's an efficient way to find if a point lies in the convex hull of a point cloud? However, the answers are confusing me or don't seem to work for me, and I have no idea why. def in_hull(p, hull): """ Copied and from the Top Original answer """ from scipy.spatial import Delaunay if not isinstance(hull,Delaunay): hull =

Checking if a point is in ConvexHull?

為{幸葍}努か 提交于 2021-02-10 08:44:45
问题 I am having trouble understanding how to compute whether an n-dimensional point is within an n-dimensional ConvexHull. A very similar question (the same) was asked here: What's an efficient way to find if a point lies in the convex hull of a point cloud? However, the answers are confusing me or don't seem to work for me, and I have no idea why. def in_hull(p, hull): """ Copied and from the Top Original answer """ from scipy.spatial import Delaunay if not isinstance(hull,Delaunay): hull =

A key in numpy.amax

。_饼干妹妹 提交于 2021-02-10 07:49:05
问题 In the Python's standard max function I can pass in a key parameter: s = numpy.array(['one','two','three']) max(s) # 'two' (lexicographically last) max(s, key=len) # 'three' (longest string) With a larger (multi-dimensional) array, we can not longer use max , but we can use numpy.amax... which unfortunately offers no key parameter . t = numpy.array([['one','two','three'], ['four','five','six']], dtype='object') numpy.amax(t) # 'two` (max of the flat array) numpy.amax(t, axis=1) # array([two,