numpy

How to convert class 'sympy.core' to 'number' or 'float' for optimization?

霸气de小男生 提交于 2021-02-11 14:13:13
问题 I'm a Python initiator and I'd like to solve the following problems, but I don't know what the cause is.I approached the problem using 'fsolve' an optimization tool. First of all, I'm trying to solve a nonlinear equation, but I've approached it in two cases. One case worked out well. But I can't find another case. First case (complete case) from sympy import * from scipy.optimize import fsolve import numpy as np y= symbols('y') b_1, b_2 = symbols ('b_1,b_2') b = 1 f = b_1 + b_2*(y/b)**2 K1 =

How to process the Time variables of OCO-2/Tropomi NETCDF4 files using Xarray?

非 Y 不嫁゛ 提交于 2021-02-11 14:02:41
问题 I am working on Tropomi .nc files. When I open the dataset using xarray, it does not process the time dimension. In Tropomi files, the time dimension is named as 'sounding_dim'. Instead of decoding the time, the returned output is just the sounding number. I have tried on OCO-2 .nc files as well. In OCO-2, the time dimension is 'sounding_id'. In case of OCO-2, the time is returned as a floating number, not as a date. The code and the output is given by: import numpy as np import xarray as xr

Failing to write in hdf5 file

天涯浪子 提交于 2021-02-11 13:59:08
问题 I am trying to create hdf5 file, but the output file is empty. I have written a python code which is supposed to run in loop and write string in the created datasets. After the file gets saved, I found that the output file is always empty. Below is the piece of code I have written: h5_file_name = 'sample.h5' hf = h5py.File(h5_file_name, 'w') g1 = hf.create_group('Objects') dt = h5py.special_dtype(vlen=str) d1 = g1.create_dataset('D1', (2, 10), dtype=dt) d2 = g1.create_dataset('D2', (3, 10),

Failing to write in hdf5 file

拈花ヽ惹草 提交于 2021-02-11 13:57:07
问题 I am trying to create hdf5 file, but the output file is empty. I have written a python code which is supposed to run in loop and write string in the created datasets. After the file gets saved, I found that the output file is always empty. Below is the piece of code I have written: h5_file_name = 'sample.h5' hf = h5py.File(h5_file_name, 'w') g1 = hf.create_group('Objects') dt = h5py.special_dtype(vlen=str) d1 = g1.create_dataset('D1', (2, 10), dtype=dt) d2 = g1.create_dataset('D2', (3, 10),

Storing L2 tick data with Python

萝らか妹 提交于 2021-02-11 13:41:53
问题 Preamble: I am working with L2 tick data. The bid/offer will not necessarily be balanced in terms of number of levels The number of levels could range from 0 to 20. I want to save the full book to disk every time it is updated I believe I want to use numpy array such that I can use h5py/vaex to perform offline data processing. I'll ideally be writing (appending) to disk every x updates or on a timer. If we assume an example book looks like this: array([datetime.datetime(2017, 11, 6, 14, 57, 8

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

时间秒杀一切 提交于 2021-02-11 13:27:36
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

有些话、适合烂在心里 提交于 2021-02-11 13:27:34
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

久未见 提交于 2021-02-11 13:27:18
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

Replacing for loops with function call inside with broadcasting/vectorized solution

a 夏天 提交于 2021-02-11 13:26:41
问题 Problem: When using broadcasting, rather than broadcasting scalars to match the arrays, the vectorized function is instead, for some reason, shrinking the arrays to scalars. MWE: Below is a MWE. It contains a double for loop. I am having trouble writing faster code that does not use the for loops, but instead, uses broadcasting/vectorized numpy. import numpy as np def OneD(x, y, z): ret = np.exp(x)**(y+1) / (z+1) return ret def ThreeD(a,b,c): value = OneD(a[0],b[0], c) value *= OneD(a[1],b[1]

Replacing for loops with function call inside with broadcasting/vectorized solution

不羁的心 提交于 2021-02-11 13:26:09
问题 Problem: When using broadcasting, rather than broadcasting scalars to match the arrays, the vectorized function is instead, for some reason, shrinking the arrays to scalars. MWE: Below is a MWE. It contains a double for loop. I am having trouble writing faster code that does not use the for loops, but instead, uses broadcasting/vectorized numpy. import numpy as np def OneD(x, y, z): ret = np.exp(x)**(y+1) / (z+1) return ret def ThreeD(a,b,c): value = OneD(a[0],b[0], c) value *= OneD(a[1],b[1]