Questions tagged [numpy-ndarray]

Numpy Ndarray refers to the N-dimensional array type that describes the collection of the same type in the Python library NumPy. Use this tag for questions related to this array type.

Numpy Ndarray refers to the N-dimensional array type that describes the collection of the same type in the Python library NumPy.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

3757 questions
1
vote
1 answer

Convert CSV File into Python Dictionary, Array and Binary File

I have a CSV file of tab-separated data with headers and data of different types which I would like to convert into a dictionary of vectors. Eventually I would like to convert the dictionary into numpy arrays, and store them in some binary format…
gciriani
  • 611
  • 2
  • 7
  • 19
1
vote
1 answer

Exponent of 3D array with numpy

Given a NxMxM array containing N, MxM square arrays, how do I calculate the N exponents of the MxM arrays. from scipy.linalg import expm U = np.random.rand(10,6,6) #Given 10 six by six arrays calculate the following: exp = expm(U) >>>…
1
vote
1 answer

Euclidean distance: results are different between python and numpy with large number of instances

I am trying two methods to implement the square result of euclidean distance. By Numpy: def inference(feature_list): distances = np.zeros(len(feature_list)) for idx, pair in enumerate(feature_list): distances[idx] =…
Tengerye
  • 1,796
  • 1
  • 23
  • 46
1
vote
2 answers

Python Concatenate and stack many matrices

I want to create a square matrix like this one where its element is a square matrix either the B square matrix or the negative identity matrix or zeros. I have created the B matrix as well as the -I and also I have created a Z matrix of zeros. B, I…
Er1Hall
  • 147
  • 2
  • 11
1
vote
1 answer

Search an array in first matrix column with numpy and get next column values

Having the following arrays (I understand the first one is call a matrix) ids = np.array([['Peter Parker','Spiderman'],['Ben Reilly','Scarlet Spider'],['Norman Osborn','Green Goblin'],['Bruce…
Allende
  • 1,480
  • 2
  • 22
  • 39
1
vote
0 answers

How does numpy array tuple indexing using np.arange() works?

Can anyone exmplain me how this type of indexing is work with numpy arrays? n=10 l=[0,1,1,1,1,0,0,1,0,1] array=np.zeros((n,2)) array[np.arange(n),l] = k I know what is the result. But I want to know how the last line of code operates(explanation)?
TassosK
  • 293
  • 3
  • 16
1
vote
2 answers

How to do dot product of a vector with a set of vectors in an array using numpy?

Given a N by M array W and a vector V of size N, how do I take the dot product V with every column of W, resulting in a 1-D array D of size M with each element of D consisting out of the dot product of V and W[:,i]. So something like V =…
PhysicsMan
  • 71
  • 1
  • 5
1
vote
1 answer

Return a distribution sample of a numpy array based on class

As a note: I am married to numpy for this task. I am attempting to write a single function that accomplish the following objectives: Load a dataset into a numpy array Split the dataset into 5 "equal" (or as equal as possible) folds For each fold,…
artemis
  • 6,857
  • 11
  • 46
  • 99
1
vote
1 answer

Numpy Array Manipulation Based off of Internal Values

I am trying to accomplish a weird task. I need to complete the following without the use of sklearn, and preferably with numpy: Given a dataset, split the data into 5 equal "folds", or partitions Within each partition, split the data into a…
artemis
  • 6,857
  • 11
  • 46
  • 99
1
vote
1 answer

Save large amount of numpy arrays in single file and use it to fit keras model

I have huge amount of numpy arrays that do not fit in RAM. Lets say millions of: np.arange(10) I want to save them on the file system in a single file, chunk by chunk. I want to read them from the file and feed them to my keras model using…
John
  • 329
  • 1
  • 20
1
vote
1 answer

Numpy arrays and comparisons with different values

For reproducibility reasons, I am sharing the data here. From column 2, I wanted to read the current row and compare it with the value of the previous row. If it is greater, I keep comparing. If the current value is smaller than the previous row's…
user10553396
1
vote
1 answer

How to combine the last 2 dimensions of Numpy Array

I already saw How to combine dimensions in numpy array? And tried that, but when I tried imgs.reshape(img.shape[:-2]+(-1)) which I assumed would be the logical extension, I get an error: can only concatenate tuple (not "int") to tuple I was…
tethys4
  • 55
  • 1
  • 11
1
vote
1 answer

Interpretation of a numpy ndarray

Suppose I want to represent an image of size H*W with 3 color channels (RGB) in a numpy 3-D array, such that the dimension is (H, W, 3). Let's take a simple example of (4,2,3). So we create an array like this - img = np.arange(24).reshape(4,2,3). In…
Supratim Haldar
  • 2,376
  • 3
  • 16
  • 26
1
vote
2 answers

Changing individual elements of numpy array based on its value

I'm trying to iterate over every element of an numpy array and change its value in a semi-random manner. The reason for that is, that I'll apply that method to different arrays: I want them to be changed but I don't want them to be changed the same…
Julia
  • 41
  • 1
  • 4
1
vote
1 answer

Create a numpy array view for specific items

Is there a way to create a view for a numpy.ndarray that will only return specific items in a specific shape? I'm working on a project with a material stress tensor matrix. I have created an ndarray sublcass that must maintain a 3x3 shape for its…
Andy Perez
  • 317
  • 3
  • 10
1 2 3
99
100