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
2 answers

How to check if a Numpy array is a subarray of another bigger array

So basically I have two arrays, and I want to check if one array is in another... I'm looking for a way to do something like this: >>> arr1 = np.array([1, 0, 0, 1, 1, 0]) >>> arr2 = np.array([0, 0, 1, 1, 1, 0]) >>> test_array = np.array([1, 1,…
1
vote
2 answers

Replace set of multiple occurring elements in Numpy array with corresponding values

Please consider the following code: arr = np.array([0, 1, 3, 5, 5, 6, 7, 9, 8, 9, 3, 2, 4, 6]) mapping = np.array([0, 10, 20, 30, 40, 55, 66, 70, 80, 90]) res = np.zeros_like(arr) min_val = 0 max_val = 10 for val in range(min_val, max_val): …
mrtpk
  • 1,398
  • 4
  • 18
  • 38
1
vote
1 answer

Issue with printing when using sorted function on drawChessboardCorners

I am having some issue while printing the output. I am getting below output array([[336.34305, 214.00804]], dtype=float32) instead of just [[336.34305, 214.00804]] Code: import cv2 import numpy as np chess_img = cv2.imread('board.jpeg') kernel =…
Amol Shah
  • 15
  • 4
1
vote
2 answers

How can I make a transparent background?

I have a .csv file which contains some data where x, y, x1, y1 are the coordinate points, and p is the value. My below code is working very well for plotting, but when I am plotting the data, I am getting a background color like the purple color. I…
Js541
  • 100
  • 1
  • 13
1
vote
1 answer

How to change axis of array slice?

I'm fairly new to numpy arrays, so any help will be much appreciated. I want to get a single slice of an n x m array along the second axis, with the result being an n x 1 array, e.g. a = np.array([[1, 2, 3], [4, 5, 6]]) Then I…
sjm220
  • 11
  • 2
1
vote
2 answers

Filter 3D python list using list or numpy

I have a python 3D list. Making it more clear, a list of list where each list is the four corner coordinate of a box. I have to filter all the boxes which are smaller than some given size. Let us suppose this is the python list. box = [[[4, 4], [4,…
Akash Kumar
  • 1,356
  • 1
  • 10
  • 28
1
vote
1 answer

Get the indexes of a numpy array inside another numpy array

I'm trying to get the indexes of a numpy array inside another numpy array, for example , I have y = array([1, 2, 3, 4, 5, 8]) x = np.array([3, 1, 8]) x is included in y, so what I would want to get is the indexes idx of the x array on the y…
Ayoub ZAROU
  • 2,387
  • 6
  • 20
1
vote
1 answer

Replace some elements of numpy.ndarray with zero given another numpy array

I'd need to know the most efficient way for the following case. There is a numpy.ndarray of shape 11k*11k for which I need to force all elements of some rows to be zero given a binary numpy array of shape 11k. A toy example could be described as…
user3000538
  • 189
  • 1
  • 2
  • 14
1
vote
1 answer

How to create a similar image dataset of mnist with shape (12500, 50,50)

How to create a similar image dataset of mnist with shape (12500, 50,50) I have a folder with 12500 images. I want to generate a datset with these images to work with sorting images in keras. I want to generate a dataset similar to mnist so that…
1
vote
1 answer

Arbitary 1D slices (elements along an axis) across an ndarray - NumPy

There are a few questions I've found that are close to what I am asking but they are different enough that they don't seem to solve my problem. I am trying to grab a 1d slice along one axis for an ndarray. As an example for a 3d array [[[ 0, 1, 2], …
Chris Uchytil
  • 140
  • 1
  • 11
1
vote
1 answer

Replace entry in specific numpy array stored in dictionary

I have a dictionary containing a variable number of numpy arrays (all same length), each array is stored in its respective key. For each index I want to replace the value in one of the arrays by a newly calculated value. (This is a very simplyfied…
1
vote
1 answer

Finding rows in numpy array with specific condition efficiently

I have two numpy array 2D. What I want to do is to find specific rows of np_weight in the np_sentence. For example: #rows are features, columns are clusters or whatever np_weight =…
sariii
  • 2,020
  • 6
  • 29
  • 57
1
vote
3 answers

How do I get the sum of values under a diagonal in numpy?

Given a 2D rectangular numpy array: a = np.array([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) I would like to take the sum of all values under the lower left to upper right diagonal , I.E. 8, 9 and 6. What is the best way to accomplish this? The…
Rutger Hofste
  • 4,073
  • 3
  • 33
  • 44
1
vote
0 answers

How to save quantized DCT coefficients as a JPEG image with Python?

I am creating a Python 3 application for steganography, specifically JPEG steganography. For this reason, I have to implement some basic JPEG compression to access the quantized DCT coefficients and embed bits into the LSBs. I have implemented all…
nodzu
  • 11
  • 2
1
vote
1 answer

Fix ValueError: shapes (1,2) and (4,4) not aligned: 2 (dim 1) != 4 (dim 0) in python

I am using sklearn with pandas to create and fit a Linear Regression Classifier to continue a chart. The code i am using to create the the arrays is: sample_data = pd.read_csv("includes\\csv.csv") sample_datat =…