Questions tagged [numpy-ndarray]

1 votes
1 replies
How to generate a 3D grid of vectors ? (each position in the 3D grid is a vector)
I want to generate a four dimensional array with dimensions (dim,N,N,N). The first component ndim =3 and N corresponds to the grid length. How ca...
asked 1 month ago
0 votes
1 replies
How to transform 3rd dimension of Numpy array loaded with ImageIO
I have a numpy array of shape (128,128,3) loaded from a PNG using ImageIO. Dimension 3 seems to represent RGB values. In this instance all value...
asked 1 month ago
0 votes
0 replies
how to truncate an array of uint8 rather than overflow, when adding a value?
I would like to implement a tool to adjust the brightness of a RGB image, which is simply a (N, M, 3)-shaped numpy array of dtype uint8. The alg...
0 votes
2 replies
create a numpy array from data on a row
My data file has a sample for each row. Each row is 400 float number. It's a 20x20 image on a single line. I have to write a numpy array with di...
asked 1 month ago
0 votes
1 replies
OpenCV ndarray image save fails after serialization
I am trying to resize an image using opencv, and then save the image to file. When I try to write the ndarray without serialization encoded_image...
3 votes
0 replies
Control how numpy casts a type via custom function
When you call np.array on an iterable of objects, it tries to cast all of them to the same type. So, for example, an iterable of several integers...
asked 1 month ago
1 votes
4 replies
How to construct a numpy array of numbers of powers of 2 more elegantly?
I would like to figure out how i can create this array without putting every single value in per hand. Is there a way how i can use the informa...
0 votes
1 replies
visual understanding of rotation by numpy.rot90 for 3D and higher order arrays, ndarrays of dimension greater than 3
I'm trying to understand a single 90 degree rotation of a 3D numpy array and find it very hard to visualize (and thus to understand the rotation...
0 votes
1 replies
cannot reshape array of size (x,) into shape (x,y,z,1)
I'm trying to convert a numpy ndarray with a shape of (2200,) to numpy ndarray with a shape of (2200,250,250,1). every single row contains an ima...
0 votes
0 replies
'numpy.ndarray' object has no attribute 'sqrt'
I am trying to obtain the std of this output using numpy.std() [[array([0.92473118, 0.94117647]), array([0.98850575, 0.69565217]), array([0.9555...
asked 1 month ago
0 votes
3 replies
how to creat a subset of sample from original size of mnist data, while keeping all 10 classes
suppose X,Y = load_mnist() where X and Y are the tensors that contain the whole mnist. Now i want a smaller proportion of the data to make my cod...
0 votes
1 replies
Iterating over successive 1-D slices along arbitrary axis of numpy array
I am writing a python package that performs various complex statistical analysis tasks along an arbitrary axis of an arbitrarily-shaped numpy arr...
0 votes
0 replies
Reading parts of file in a 2D NumPy array in Python3
I have a file with the following format: ###block 1 0011000000 0100010000 1100000000 1110101000 ###block 2 110010 001000 010000 111111 I want...
asked 1 month ago
-1 votes
2 replies
Adding Numpy ndarray into dataframe
I would like to add a numpy array to each row in my dataframe: I do have a dataframe holdings some data in each row and now i like to add a new c...
1 votes
1 replies
Time comparison of numpy argmax and sort functions
I am trying to find the column with maximum column-sum of a 2D matrix in numpy. For example: Let A = [[1, 2, 3], [0, 1, 4], [0, 0, 1]] The sums...
asked 1 month ago
1 votes
2 replies
pytorch compute pairwise difference: Incorrect result in NumPy vs PyTorch and different PyTorch versions
Suppose I have two arrays, and I want to calculate row-wise differences between every two rows of two matrices of the same shape as follows. This...
0 votes
0 replies
identity of a matrix [duplicate]
I am getting a very strange value for my (1,1) entry for my BinvA matrix I am just trying to invert B matrix and do a (B^-1)A multiplication. I...
asked 1 month ago
0 votes
1 replies
Synchronised numpy 2D array counter with locks
I want to parallelize a method that operates on a shared numpy 2D array. My original application is part of a research and very complicated, ho...
0 votes
1 replies
How to loop numpy ndarray by using cupy? Is will really improve execution time?
I have two numpy ndarray with same size[512 X 512]. I want to change one array according to other array value. But the execution time is really l...
asked 2 months ago
1 votes
2 replies
What is the fastest way to see whether values in a numpy OrderedDict are the same in another OrderedDict?
I am trying to identify whether two values held in different numpy orderdict objects are the same. Both dictionaries were created by using the...
asked 2 months ago
0 votes
1 replies
What is the difference between numpyArr[:,:,:,c] and numpyArr[…,c]?
I've beeen taking deep learning course on coursera. While I was doing my assignment I saw one piece of code on the github. 1. numpyArr[...,c] 2...
0 votes
1 replies
Fastest way to determine if two points are closest to one another
My problems consists of the following: I am given two pairs angles (in spherical coordinates) which consists of two parts--an azimuth and a colat...
-1 votes
1 replies
a loop to iterate on a numpy array columns (with dimensionality of either 1D or 2D)
I'm trying to write a function that gets a numpy array, INPUT, and passes it's columns, one by one to another function. the INPUT array is either...
asked 2 months ago
0 votes
1 replies
How to send numpy array to sagemaker endpoint using lambda function
How to invoke sagemaker endpoint with input data type numpy.ndarray. I have deployed a sagemaker model and trying to hit it using lambda function...
0 votes
1 replies
Concatenate numpy arrays in for loop
I've split an image up into 16 figures to plot regression and now I want to join it back together into one image. I've written a for loop to do...