numpy

Print highest peak value of the frequency domain plot

不羁岁月 提交于 2021-01-28 20:45:01
问题 I've attempted to plot the oscillations of my home made quad in the time and frequency domain. How do I print the value of my highest peak in the frequency domain plot? code: import matplotlib.pyplot as plt import numpy as np from scipy import fft, arange csv = np.genfromtxt ('/Users/shaunbarney/Desktop/Results/quadOscillations.csv', delimiter=",",dtype=float) x = csv[:,0] y = csv[:,1] x = x - 6318 #Remove start offset av=0 for i in xrange(1097): #Calculate average sampling time in seconds

How to reshape an array while preserving order?

时间秒杀一切 提交于 2021-01-28 20:11:52
问题 I am trying to reshape an array from shape (a,b,c) to (b,c,a) such that if my table is B and my new table is B1 then B[n,:,:]=B1[:,:,n] for some n between 0 and a. For example I tried something like, B=np.array([[[1],[2],[23]],[[2],[4],[21]],[[6],[45],[61]],[[1],[34],[231]]]) B1=np.reshape(B,(3,1,4)) But B[1,:,:]=array([[ 2],[ 4],[21]]) and B1[:,:,1]=array([[ 2],[21],[ 1]]) which is not what I want I would've expected them to be equal. Any suggestions would be greatly appreciated. 回答1: In

Problems while taking screenshots of a window and displaying it with OpenCV

别说谁变了你拦得住时间么 提交于 2021-01-28 20:10:52
问题 When i run this code on my desktop pc it runs fine. but when i run it op my laptop something goes wrong when i set the bounding box for the image grab to the bounding box of the windows calculator and the screen recording of the window and places it self a little up and to the left. import cv2 import numpy as np from PIL import ImageGrab import win32gui def windowGrab(window_title=None): if window_title: global hwnd hwnd = win32gui.FindWindow(None, window_title) if hwnd: win32gui

Modifying values of a sub-array in python

送分小仙女□ 提交于 2021-01-28 20:10:36
问题 I want to modify the values of a sub-array in Python but it does not work the way I would like to. Here is an example, first let us consider the numpy arrays : A = np.reshape(np.arange(25),(5,5)) and B = np.ones((2,3)) If we check the values of A we get : >>> A array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) I want to replace in A the values of the sub-array A[:,[1,3,4]][[1,3],:] by the values of B. So what I am doing is the

Tensorflow error in Colab - ValueError: Shapes (None, 1) and (None, 10) are incompatible

倖福魔咒の 提交于 2021-01-28 19:49:31
问题 I'm trying to execute a small code for NN using the MNIST dataset for characters recognition. When it comes to the fit line I get ValueError: Shapes (None, 1) and (None, 10) are incompatible import numpy as np #Install Tensor Flow try: #Tensorflow_version solo existe en Colab %tensorflow_version 2.x except Exception: pass import tensorflow as tf tf.__version__ mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() print(x_train.shape) print(x_test.shape)

Using boost numpy with visual studio 2019 and python 3.8

こ雲淡風輕ζ 提交于 2021-01-28 19:12:01
问题 I want to use Boost Numpy (boost version 1.72) with Visual Studio 2017 and Python 3.8. In my test program which includes I get a link error "boost_numpy38-vc141-mt-gd-x32-1_72.lib". I cannot find the file "boost_numpy38-vc141-mt-gd-x32-1_72.lib" anywhere, it is not created when building the binaries (bootstrap + .\b2) and it is nowhere to be found on the binary repositories at Sourceforge (https://sourceforge.net/projects/boost/files/boost-binaries/ ). Anybody any clue? 回答1: Building Boost

How to understand numpy's combined slicing and indexing example

百般思念 提交于 2021-01-28 19:08:18
问题 I am trying to understand numpy's combined slicing and indexing concept, however I am not sure how to correctly get the below results from numpy's output (by hand so that we can understand how numpy process combined slicing and indexing, which one will be process first?): >>> import numpy as np >>> a=np.arange(12).reshape(3,4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> i=np.array([[0,1],[2,2]]) >>> a[i,:] array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]], [[ 8, 9, 10, 11], [ 8, 9,

rpy2 error with datetime64[ns] pandas series

≯℡__Kan透↙ 提交于 2021-01-28 18:25:55
问题 How can one pass datetime64[ns] data to R from rpy2? The following simple case: import pandas as pd import rpy2.robjects as robjs from rpy2.robjects import pandas2ri pandas2ri.activate() dti = pd.date_range('2018-01-01', periods=3, freq='H') robjs.r.summary(dti) fails with a ValueError: ValueError: Unknown numpy array type "datetime64[ns]". with rpy2 version 3.3.4 and pandas 1.0.5. 回答1: Instead of passing DatetimeIndex to R as you do: dti = pd.date_range('2018-01-01', periods=3, freq='H')

python Spyder not importing numpy

泪湿孤枕 提交于 2021-01-28 17:51:36
问题 I am writing a script using python Spyder 2.2.5 with Windows 7, python 2.7 At the very beginning I have tried all the import ways: from numpy import * or import numpy and also import numpy as np And, for each an every line where I use numpy I am getting an error when compiling QR10 = numpy.array(QR10,dtype=float) QR20 = numpy.array(QR20,dtype=float) QR11 = numpy.array(QR11,dtype=float) QR21 = numpy.array(QR21,dtype=float) However, even with this 30 errors, the script works if I run it.... Any

python Spyder not importing numpy

点点圈 提交于 2021-01-28 17:47:16
问题 I am writing a script using python Spyder 2.2.5 with Windows 7, python 2.7 At the very beginning I have tried all the import ways: from numpy import * or import numpy and also import numpy as np And, for each an every line where I use numpy I am getting an error when compiling QR10 = numpy.array(QR10,dtype=float) QR20 = numpy.array(QR20,dtype=float) QR11 = numpy.array(QR11,dtype=float) QR21 = numpy.array(QR21,dtype=float) However, even with this 30 errors, the script works if I run it.... Any