115,242 questions
0
votes
0
answers
76
views
f2py `-DF2PY_REPORT_ATEXIT` flag not working
I am using Numpy's F2PY to compile some Fortran code for use in Python, and I am trying to test the performance of the F2PY-generated interface using the -DF2PY_REPORT_ATEXIT compilation flag. ...
2
votes
0
answers
88
views
How to correctly install numpy/scipy with openBLAS backend via conda?
I'm a windows user. I want to install numpy/scipy using openBLAS threading via conda. If I make an environment like this
name: test
channels:
- conda-forge
dependencies:
- python
- pip
- numpy
...
2
votes
2
answers
149
views
Vectorising weight average over time
I'm trying to calculate the quality property of a storage tank over time. The quality is the weighted average of the previous period's quality (weighted by closing stock balance) and the current ...
2
votes
2
answers
110
views
Immvision thinks ndarray not being passed while type() shows it is
I am trying to make a Python imgui_bundle cartopy app and even though I am making an ndarray, I get an error stating I need a numpy.ndarray even though when I type() it states it is an numpy.ndarray. ...
2
votes
1
answer
132
views
Transpose matrix about anti diagonal axis in numpy
I want to take the transpose of a square matrix about the anti-diagonal axis:
I tried to adapt the code from a C++ post to run on Python to transpose my matrix:
import numpy as np
def swapEl(mat):
...
2
votes
2
answers
120
views
How to re-arrange / swizzle element pairs in a flat array using numpy?
I'm working with a continuous, 1-dimensional ndarray of coordinates in the form [x1, y1, z1, x2, y2, z2, ...]. I need to now swap the order from X,Y,Z to X,Z,Y, so that the output array has the form [...
Best practices
0
votes
6
replies
150
views
Iterating a 2D Array Diagonally in Python
I have an array with almost infinite dimensions. I would like to iterate it from top left to bottom right, and when a certain threshold is reached iteration can be stoped.
I create our test array.
mat ...
Advice
0
votes
4
replies
139
views
Writing a Neural Network which can have an arbitrary number of hidden layers, could someone tell me if this is the best way to do it?
#Multiple Layers
import numpy as np
class NeuralNetwork:
def __init__(self, input_size, hiddenLayerSizes, output_size):
self.input_size = input_size
self.hiddenLayerSizes = ...
2
votes
0
answers
97
views
Base attribute of a numpy array after dumping/loading with dill points to garbage rather than set to None
I need to refer to the base attribute of arrays to keep track of whether I am currently handling some view of it or the base array itself.
However, if I dump the array to a file with dill and load it ...
0
votes
1
answer
86
views
Saving and loading an instance of derived class with pickle
As explained in this answer it is possible to save an instance of a class and load it again using numpy save/load routines.
However, if I do this with a derived class, I lose the reference to the ...
0
votes
1
answer
79
views
uncommon "setting an array with a sequence" error
im struggle with an error when creating MRE.
why these code :
from pandas import DataFrame as df
import numpy as np
from sklearn.neighbors import NearestNeighbors as nrb
from sklearn.decomposition ...
2
votes
1
answer
142
views
Keep unique pairs of values from two vectors in numpy
Suppose I have two integer numpy vectors a0 and a1 of the same length. I want to return unique pairs of elements of a0 and a1. For instance:
a0 = np.asarray([0, 1, 4, 1, 0, 4]) # --> b0 = np....
2
votes
2
answers
194
views
Add character to value in Pandas Dataframe column if value is specific length
I am trying to reformat the values in a dataframe column for a person's height from, for example, 5'8" to 5 Feet 8 Inches and I figure that I can at least replace the apostrophe and double quotes ...
1
vote
1
answer
104
views
KDTree 2d index searching based on pivot_table vector error
i want find 2d index(from PCA). based on pivot_table vector at my custom metric. fastly. that's why im using KDTree. but because it, these error is occur:
ValueError Traceback (most recent call last)
...
Best practices
1
vote
13
replies
184
views
Series cancelations accumulate errors, how to avoid?
import math
import matplotlib.pyplot as plt
import numpy as np
m=50
def taylor_cos(x,n):
sum=0
for i in range(0, n):
sum=sum+ (((-1)**i) * (x**(2*i)) / math.factorial(2*i))
...