115,220 questions
Score of -2
0 answers
63 views
How to use the function 'texts_to_sequences' from tensorflow, Tokenizer package?
Importing packages
import json
import random
import numpy as np
from nltk import word_tokenize, pos_tag
from nltk.stem import WordNetLemmatizer, PorterStemmer
from tensorflow.keras.models import ...
Score of -4
0 answers
139 views
NumPy neural network from scratch for regression: is my implementation correct, and what hyperparameters or feature engineering should I try next? [closed]
I am implementing a 3-layer dense neural network from scratch using NumPy for a regression problem. I am not using TensorFlow, PyTorch, Keras, or any neural-network library because I want to ...
Score of 2
1 answer
149 views
How can I make numpy arrays the same shape before doing conditional computations?
Let's say I have a conditional calculation like this
import numpy as np
def foo(a, b, c):
if a <= 0 or c == 0:
return foo_special(a, b, c)
return foo_normal(a, b, c)
def ...
Score of -4
0 answers
65 views
Why does NumPy slicing with a positive step return an empty array when start index is greater than end index? [duplicate]
I am learning NumPy slicing and I am confused about why this slice returns an empty array:
import numpy as np
array = np.array([
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
...
Score of -2
0 answers
131 views
Convert a Numpy code to a Dask Array in order to parallelize the code
I am facing some issues concerning memory error due to a huge array that is used in my code. Recently I found Dask Array as a possible solution to parallelize the tasks and be able to process the data....
Score of 1
2 answers
185 views
Create a new column in pandas conditionally based on two other columns that may have overlapping values
In a dataset that contains X and Y coordinates, I want to assign a value in a new column based on the (X,Y) pair in a given row. Imagine a data set that contains the red points shown in the image ...
Score of 1
2 answers
158 views
Working with huge uint8 array without sufficient memory
I am working with huge matrix of small numbers using numpy and getting the following error:
MemoryError: Unable to allocate 9.72 TiB for an array with shape (3268760, 3268760) )data type uint8"
...
Score of 2
2 answers
293 views
Trying to Change A Pixel in Python
I'm trying to change a pixel to red. However, when I run the code, the pixel remains unedited. Can you help?
import cv2 as cv
import os
import matplotlib.pyplot as plt
def readAndWriteImage():
...
Score of 2
1 answer
181 views
Check if matrix contains only specific values in numpy
I have large matrices that contain both real numbers and nan. I want to find the most efficient way to determine if a matrix contains only zeros and/or nan entries. If it does, the code should return ...
Score of 2
0 answers
356 views
Why do C- and Fortran-ordered NumPy arrays show the same L1 cache-miss percentage when formatting a row?
Consider
import numpy as np
N = 2000
a = np.ones((N, 5*N), dtype=np.float64, order="C")
for _ in range(1000):
x = np.array2string(a[0], threshold=np.inf)
and
import numpy as np
N = ...
Score of 3
1 answer
154 views
Full string not added to dictionary in loop [duplicate]
I am running into an issue where my dictionary is not picking up full strings attached to variables, but instead just the first letter.
import numpy as np
import random
trials = 5
d = {'trial': np....
Score of 4
2 answers
190 views
How can I boxplot values that wrap around using matplotlib?
I want to show the distribution of angle estimations using a boxplot. The problem is that angles wrap around (I chose +-180° as the wrapping point, but the same applies to 0/360°).
Matplotlibs boxplot ...
Score of -1
1 answer
118 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. ...
Score of 2
0 answers
129 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
...
Score of 2
3 answers
185 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 ...