I’m trying to get a “pythonic” way or using a library (anything except “for” loops) for doing this. Expected result: However, I get: This doesn’t work for me as I need to multiply twice the factor (2) for the position 0 if, through the index, the 0 position repeats n amount…
Tag: numpy
grid with circular distances python
I have a 2d grid of dim q(rows) p(columns). The element of the grid are the indices of the element itself. So the element a[i,j]=(i,j). Now I need to create pair-wise distances between these points with circularity constraint, meaning that the element distance(a[i,p-1],a[i,0])=1 (I am using 0-index based matr…
How to sort aggregated numpy array?
My first post on stackoverflow + am very new to programming. Apologies in advance for any poor formatting and missing information. :) I aggregated two columns in a csv file (one column of seller names, the other of transactional amounts) to find how much each seller has made in total: I want to sort it in des…
How to define an array without defining its elements?
I want to optimize a problem in Python using scipy. To achieve this goal: I define an array of a certain length, but without defining its elements explicitly. Then, I need to use this array to optimize the problem. In the last step, I want to print this array as a result. Here is the simple example: Answer Py…
Numpy apply along axis based on row index
Trying to apply numpy inbuilt function apply_along_axis based on row index position OP: The function: Op: But is there a way to use this function based on row index position for example, if its a even row index then add 10 and if its a odd row index then add 50 Sample: Answer When iterating on array, directly…
Cumulatively merge rows with the same index
In python pandas, I have a dataframe which looks something like this: Some of the dates are repeated, with a different count value. I would like to merge these values into one row like this: If it’s any help the data source is a CSV file. There is likely a way to do this in a for loop but I
Conformal plotting python
I’m working on the joukowsky transformation for plotting airfoils and I’m trying to do so with python. The conformal mapping should be pretty straight forward but can’t seem to find a guide on how to approach the problem on python. by the math: According to the theory, by plotting z i should…
numpy polynomial.Polynomial.fit() gives different coefficients than polynomial.polyfit()
I do not understand why polynomial.Polynomial.fit() gives coefficients very different from the expected coefficients : Gives : The two first results are OK, and thanks to this answer I understand why the two arrays are in reversed order. However, I do not understand the signification of the third result. The …
How to Install Numpy in PyPy on Windows
I want to install Numpy on PyPy on windows but I cannot. Here is my errors: Answer You don’t have any compiler on your system, so PyPy can’t compile the packages. notice the line error: Microsoft Visual C++ 14.0 is required. Get it with “Build Tools for Visual Studio”: https://visualst…
I have a data type problem in the text classification problem
I want to build deep learning classifiers for Kickstarter campaign prediction. I have a problem with the part of the model but I can not solve this. My code: In this point, I am getting ValueError: Failed to find data adapter that can handle input: <class ‘scipy.sparse.csr.csr_matrix’>, (<…