numpy

numpy: summing every element of numpy array with every element of another

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 13:01:58
问题 I'm coming to python from Matlab. In Matlab, given two vectors that are not necessarily the same length, they can be added if one is a row vector and one is a column vector. v1 = [1 3 5 7] v2 = [2 4 6]' v1 + v2 ans = 3 5 7 9 5 7 9 11 7 9 11 13 I am trying to produce the same behavior in python given two numpy arrays. Looping first came to mind: import numpy as np v1 = np.array([1,3,5,7]) v2 = np.array([2,4,6]) v3 = np.empty((3,4,)) v3[:] = np.nan for i in range(0,3): v3[i,:] = v1 + v2[i] Is

numpy: summing every element of numpy array with every element of another

大憨熊 提交于 2021-01-28 13:01:51
问题 I'm coming to python from Matlab. In Matlab, given two vectors that are not necessarily the same length, they can be added if one is a row vector and one is a column vector. v1 = [1 3 5 7] v2 = [2 4 6]' v1 + v2 ans = 3 5 7 9 5 7 9 11 7 9 11 13 I am trying to produce the same behavior in python given two numpy arrays. Looping first came to mind: import numpy as np v1 = np.array([1,3,5,7]) v2 = np.array([2,4,6]) v3 = np.empty((3,4,)) v3[:] = np.nan for i in range(0,3): v3[i,:] = v1 + v2[i] Is

numpy: summing every element of numpy array with every element of another

天大地大妈咪最大 提交于 2021-01-28 13:01:12
问题 I'm coming to python from Matlab. In Matlab, given two vectors that are not necessarily the same length, they can be added if one is a row vector and one is a column vector. v1 = [1 3 5 7] v2 = [2 4 6]' v1 + v2 ans = 3 5 7 9 5 7 9 11 7 9 11 13 I am trying to produce the same behavior in python given two numpy arrays. Looping first came to mind: import numpy as np v1 = np.array([1,3,5,7]) v2 = np.array([2,4,6]) v3 = np.empty((3,4,)) v3[:] = np.nan for i in range(0,3): v3[i,:] = v1 + v2[i] Is

numpy: summing every element of numpy array with every element of another

流过昼夜 提交于 2021-01-28 12:57:49
问题 I'm coming to python from Matlab. In Matlab, given two vectors that are not necessarily the same length, they can be added if one is a row vector and one is a column vector. v1 = [1 3 5 7] v2 = [2 4 6]' v1 + v2 ans = 3 5 7 9 5 7 9 11 7 9 11 13 I am trying to produce the same behavior in python given two numpy arrays. Looping first came to mind: import numpy as np v1 = np.array([1,3,5,7]) v2 = np.array([2,4,6]) v3 = np.empty((3,4,)) v3[:] = np.nan for i in range(0,3): v3[i,:] = v1 + v2[i] Is

Datetime comparisons in python

爷,独闯天下 提交于 2021-01-28 12:01:13
问题 I have a file with two different dates: one has a timestamp and one does not. I need to read the file, disregard the timestamp, and compare the two dates. If the two dates are the same then I need to spit it to the output file and disregard any other rows. I'm having trouble knowing if I should be using a datetime function on the input and formatting the date there and then simply seeing if the two are equivalent? Or should I be using a timedelta? I've tried a couple different ways but haven

Can I find out if one numpy vector appears as a slice of another?

眉间皱痕 提交于 2021-01-28 11:51:46
问题 I want to find out if my numpy vector, needle , appears inside another vector, haystack , as a slice, or contiguous sub-vector. I want a function find(needle, haystack) that returns true if and only if there are possible integer indexes p and q such that needle equals haystack[p:q] , where "equals" means elements are equal at all positions. Example: find([2,3,4], [1,2,3,4,5]) == True find([2,4], [1,2,3,4,5]) == False # not contiguous inside haystack find([2,3,4], [0,1,2,3]) == False #

Passing float to a nested for loop and storing output

≯℡__Kan透↙ 提交于 2021-01-28 11:32:03
问题 I have a strong background in Matlab, and I am trying to switch to python. I am trying to write a nested for loop with numpy array and storing output values. My code reads like: import numpy as np import math # T parameter kk = np.arange(0, 20, 0.1) print(len(kk)) # V parameter pp = np.arange(1, 5, 1) print(len(pp)) a = len(kk) b = len(pp) P = np.zeros((a,b)) for T in kk: print(T) for V in pp: print(V) P = math.exp(-T*V/10) print(P) Explanation/Question kk , pp are the vectors. In for loop(s)

Solving set of Boundary Value Problems

点点圈 提交于 2021-01-28 11:26:25
问题 I am trying to solve a set of boundary value problems given by 4 differential equations. I am using bvp_solver in python, and I am getting errors which state 'invalid value encountered in division'. I am assuming this means I am dividing by NaN or 0 at some point, but I am unsure where. import numpy as np from scipy.integrate import solve_bvp import matplotlib.pyplot as plt %matplotlib inline alpha = 1 zeta = 1 C_k = 1 sigma = 1 Q = 30 U_0 = 0.1 gamma = 5/3 theta = 3 m = 1.5 def fun(x, y): U,

Tensorflow-Numpy OSError: [WinError 193] %1 is not a valid Win32 application

ぐ巨炮叔叔 提交于 2021-01-28 11:26:24
问题 I am trying to import Keras (using tensorflow), and I am getting this error. I have tried everything I found in the Internet, but still does not work. Please I will appreciate a lot if you help me. I have read is something with the 32bits and 64bits versions. I have tried everything (downloaded and uninstalled several times everything). I am pretty sure the problem is with the numpy DLL. Traceback (most recent call last): File "versiones.py", line 2, in <module> import scipy File "C:\Users

Replace a single character in a Numpy list of strings

孤人 提交于 2021-01-28 11:20:55
问题 I have a Numpy array of datetime64 objects that I need to convert to a specific time format yyyy-mm-dd,HH:MM:SS.SSS Numpy has a function called datetime_as_string that outputs ISO8601 (yyyy-mm-ddTHH:MM:SS.SSS) time, which is extremely close to what I want, the only difference being there is a T where I want a comma. Is there a way to quickly swap the "T" for a ","? Here is an example data set: offset = np.arange(0, 1000) epoch = np.datetime64('1970-01-01T00:00:00.000') time_objects = epoch +