numpy

numpy element-wise multiplication of an array and a vector

妖精的绣舞 提交于 2021-02-04 15:14:10
问题 I want to do something like this: a = # multi-dimensional numpy array ares = # multi-dim array, same shape as a a.shape >>> (45, 72, 37, 24) # the relevant point is that all dimension are different v = # 1D numpy array, i.e. a vector v.shape >>> (37) # note that v has the same length as the 3rd dimension of a for i in range(37): ares[:,:,i,:] = a[:,:,i,:]*v[i] I'm thinking there has to be a more compact way to do this with numpy, but I haven't figured it out. I guess I could replicate v and

Convert XYZ point cloud to grayscale image

淺唱寂寞╮ 提交于 2021-02-04 14:13:12
问题 Everyone I'm trying to convert point cloud (X, Y, Z) to the grayscale image using python. I learned that the grayscale image could be generated by a Numpy array. But what I have now is a set of points which contains X, Y and height. I wanna generate a grayscale image based on X, Y and grayscale value which is Height. Can someone give me an idea about this? Thanks beforehand. Rowen 回答1: let's assume that the X,Y are arranged so they will form a grid (which is mandatory in order to build a

How to calculate mean color of image in numpy array?

不羁的心 提交于 2021-02-04 13:11:05
问题 I have an RGB image that has been converted to a numpy array. I'm trying to calculate the average RGB value of the image using numpy or scipy functions. The RGB values are represented as a floating point from 0.0 - 1.0, where 1.0 = 255. A sample 2x2 pixel image_array: [[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]] I have tried: import numpy numpy.mean(image_array, axis=0)` But that outputs: [[0.5 0.5 0.5] [0.5 0.5 0.5]] What I want is just the single RGB average

Is it possible to install scipy under pypy?

落爺英雄遲暮 提交于 2021-02-04 13:08:15
问题 I created a virtualenv with pypy and tried to install scipy, but installation ended with the following error: distutils.errors.DistutilsError: Setup script exited with error: Command "cc -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.2/numpy/core/include

Is it possible to install scipy under pypy?

微笑、不失礼 提交于 2021-02-04 13:07:51
问题 I created a virtualenv with pypy and tried to install scipy, but installation ended with the following error: distutils.errors.DistutilsError: Setup script exited with error: Command "cc -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.2/numpy/core/include

How to calculate mean color of image in numpy array?

做~自己de王妃 提交于 2021-02-04 13:07:43
问题 I have an RGB image that has been converted to a numpy array. I'm trying to calculate the average RGB value of the image using numpy or scipy functions. The RGB values are represented as a floating point from 0.0 - 1.0, where 1.0 = 255. A sample 2x2 pixel image_array: [[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]] I have tried: import numpy numpy.mean(image_array, axis=0)` But that outputs: [[0.5 0.5 0.5] [0.5 0.5 0.5]] What I want is just the single RGB average

Is it possible to install scipy under pypy?

泪湿孤枕 提交于 2021-02-04 13:07:19
问题 I created a virtualenv with pypy and tried to install scipy, but installation ended with the following error: distutils.errors.DistutilsError: Setup script exited with error: Command "cc -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.2/numpy/core/include

Is it possible to install scipy under pypy?

醉酒当歌 提交于 2021-02-04 13:06:41
问题 I created a virtualenv with pypy and tried to install scipy, but installation ended with the following error: distutils.errors.DistutilsError: Setup script exited with error: Command "cc -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.2/numpy/core/include

How to calculate mean color of image in numpy array?

一笑奈何 提交于 2021-02-04 13:04:08
问题 I have an RGB image that has been converted to a numpy array. I'm trying to calculate the average RGB value of the image using numpy or scipy functions. The RGB values are represented as a floating point from 0.0 - 1.0, where 1.0 = 255. A sample 2x2 pixel image_array: [[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]] I have tried: import numpy numpy.mean(image_array, axis=0)` But that outputs: [[0.5 0.5 0.5] [0.5 0.5 0.5]] What I want is just the single RGB average

Implementation of the Gauss-Newton method from Wikipedia example

岁酱吖の 提交于 2021-02-04 12:36:07
问题 I'm relatively new to Python and am trying to implement the Gauss-Newton method, specifically the example on the Wikipedia page for it (Gauss–Newton algorithm, 3 example). The following is what I have done so far: import scipy import numpy as np import math import scipy.misc from matplotlib import pyplot as plt, cm, colors S = [0.038,0.194,.425,.626,1.253,2.500,3.740] rate = [0.050,0.127,0.094,0.2122,0.2729,0.2665,0.3317] iterations = 5 rows = 7 cols = 2 B = np.matrix([[.9],[.2]]) # original