numpy

How can I append to a numpy array without reassigning the result to a new variable?

我是研究僧i 提交于 2021-02-08 06:39:40
问题 I have a matrix M with dimensions (m, n) and I need to append new columns to it from a matrix L with dimensions (m, l) . So basically I will end up with a matrix (m, n + l) . No problem in doing this, I can use: numpy.concatenate numpy.vstack numpy.append in the following fashion np.command(M, L) and it will return me a new matrix. The problem arises with the fact that I need to append many many matrices to the original matrix, and the size of these matrices L are not known beforehand. So I

How to create a numpy array to describe the vertices of a triangle?

若如初见. 提交于 2021-02-08 06:22:23
问题 I like to use Numpy to create an array of vertices that is to be passed into glsl . Vertices will be a numpy array that comprises the info of 3 vertex. Each vertex consist of: pos = (x, y) a 64-bit signed floating-point format that has a 32-bit R component in bytes 0..3, and a 32-bit G component in bytes 4..7, and color = (r, g, b) a 96-bit signed floating-point format that has a 32-bit R component in bytes 0..3, a 32-bit G component in bytes 4..7, and a 32-bit B component in bytes 8..11 i.e.

Calculating amplitude from np.fft

纵饮孤独 提交于 2021-02-08 06:16:56
问题 I appear to be calculating incorrect amplitudes for the original waves using np.fft.fft. The plot of the fft shown is shown, as you can see the amplitudes shown are around 3 and 1.5, but if you look at the code I'm using amplitudes 7 and 3 to generate the signal. This plot should have two spikes which go up to y=3 at x=13 and y=7 at x=15 What do I need to do to see the proper amplitudes (3 and 7) in my graph? I can experimentally see the constant I need to multiply my amplitudes by is around

Generating equidistance points along the boundary of a polygon but CW/CCW

房东的猫 提交于 2021-02-08 06:15:36
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

Generating equidistance points along the boundary of a polygon but CW/CCW

╄→гoц情女王★ 提交于 2021-02-08 06:15:32
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

Generating equidistance points along the boundary of a polygon but CW/CCW

ε祈祈猫儿з 提交于 2021-02-08 06:15:08
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

how to add error bars to histogram diagram in python

这一生的挚爱 提交于 2021-02-08 05:33:42
问题 Hi I want to add error bars to the histogram within this code.I have seen few post about it but I didn't find them helpful.this code produce random numbers with Gaussian distribution and a kernel estimation apply to it.I need to have errorbars to estimate how much the histogram is inaccurate with changing the bandwidth from random import * import numpy as np from matplotlib.pyplot import* from matplotlib import* import scipy.stats as stats def hist_with_kde(data, bandwidth = 0.3): #set number

Converting an array datatime.datetime to float

牧云@^-^@ 提交于 2021-02-08 05:23:31
问题 Is it possible to convert something like this; array([datetime.datetime(2014, 2, 1, 0, 0, 0, 100000), datetime.datetime(2014, 2, 1, 0, 0, 0, 300000), datetime.datetime(2014, 2, 1, 0, 0, 0, 500000), ..., datetime.datetime(2014, 2, 1, 19, 30, 0, 500000), datetime.datetime(2014, 2, 1, 19, 30, 0, 700000), datetime.datetime(2014, 2, 1, 19, 30, 0, 900000)], dtype=object) to this: array([ 1.39277301e+09, 1.39277301e+09, 1.39277301e+09, ..., 1.39285442e+09, 1.39285442e+09, 1.39285442e+09]) I would

How to add multiple extra columns to a NumPy array

倖福魔咒の 提交于 2021-02-08 05:16:33
问题 Let’s say I have two NumPy arrays, a and b : a = np.array([ [1, 2, 3], [2, 3, 4] ]) b = np.array([8,9]) And I would like to append the same array b to every row (ie. adding multiple columns) to get an array, c : b = np.array([ [1, 2, 3, 8, 9], [2, 3, 4, 8, 9] ]) How can I do this easily and efficiently in NumPy? I am especially concerned about its behaviour with big datasets (where a is much bigger than b ), is there any way around creating many copies (ie. a.shape[0] ) of b ? Related to this

improve speed when reading a binary file

ぃ、小莉子 提交于 2021-02-08 05:13:29
问题 I have a large binary file that I want to read in an array. The format of the binary files is: there is an extra data of 4 bytes at the start and end of each row that I'm not using; in between I have 8 bytes values I'm doing it like this: # nlines - number of row in the binary file # ncols - number of values to read from a row fidbin=open('toto.mda' ,'rb'); #open this file temp = fidbin.read(4) #skip the first 4 bytes nvalues = nlines * ncols # Total number of values array=np.zeros(nvalues