115,247 questions
Best practices
0
votes
5
replies
89
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
112
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
84
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
75
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
69
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
139
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....
1
vote
2
answers
193
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
101
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
180
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))
...
1
vote
1
answer
191
views
Python/numpy - 2D FFT does not recover the analytical solution
I am working on a code that calculates the 2D FFT of a function as a first step. I am testing it with the function exp(-r)/r, with r=sqrt(x²+y²) which has the analytical Hankel transform of 1/sqrt(r²+...
Best practices
0
votes
6
replies
94
views
Is there a simple way to take bitwise-and of a pandas series?
I have a pandas series of a bunch of 32 bit integers, and I'd like to roll through with series.rolling and get the bitwise-and of all the values in the window, basically trying to do this except that ...
Advice
0
votes
2
replies
136
views
How should a beginner approach learning NumPy before using it with real datasets
I’m a beginner learning NumPy and Data Science. I understand basic operations such as array creation, indexing, slicing, and simple computations.
However, when I try to follow tutorials that use NumPy ...
Best practices
0
votes
4
replies
126
views
Efficient, parallelized graph6 parsing with numpy or SIMD?
I have a multigraph class in Python that is used as a base for simple undirected, unlooped graphs.
I wrote my own graph6 parser based on the advice in the SO post.
NetworkX implements it in a similar ...
Advice
0
votes
2
replies
105
views
Python mandelbrot set iteration slider
I've got a class project to do, it's supposed to display the mandelbrot set with a customizable colour map and a max_iter slider. I've got the colour map radio buttons working, but I can't manage the ...
-5
votes
2
answers
205
views
How can I remove unnecessary layers from a nested array? [closed]
I have a "deeply nested" NumPy array like this:
array = [
[
[
[ "data . . . "],
]
],
[
...
