115,228 questions
Score of 0
2 answers
104 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
264 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
168 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 1
0 answers
148 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
151 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
180 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 -2
0 answers
157 views
How do I plot this function for all values of the numpy array?
I want some straightforward way to model a for all values of the array like in a for loop. the only way I found was using filtered arrays which is very very tedious.
This function takes a number turns ...
Score of -1
1 answer
114 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
109 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
174 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 ...
Score of 2
2 answers
119 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. ...
Score of 2
1 answer
141 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):
...
Score of 2
2 answers
133 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
165
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
147
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 = ...