numpy

2D to 3D numpy array by blocks

2D to 3D numpy array by blocks Question: I have the following 2D dataframe conc corresponding to gas concentrations on 4 layers at a series of wavelengths wl : conc = wl gas1 gas2 gas3 layer 0 5000 10 13 250 1 1 5000 20 14 260 2 2 5000 30 15 270 3 3 …

Total answers: 4

why numpy.in1d() works more faster in my example but my object?

why numpy.in1d() works more faster in my example but my object? Question: The 2 tables I have to deal with in my object like this: TABLE1: code_material yield 1000100001 1000 1000100002 500 1000100003 1024 where code_material is a ten-digit number whose value does not exceed 4e+9 TABLE2: code_material_manufacturing input/output code_material qty 1000100001 1000154210 IN 100 …

Total answers: 1

swap columns from multidimensional array

swap columns from multidimensional array Question: I have this array: my_array = np.arange(1216800).reshape(2, 100, 78, 78) The shape now is: (2, 100, 78, 78) and I want to reorder to : (100, 78, 78, 2). I tried something like: my_array[:, :, 2, :], my_array[:, :, :, 3] = my_array[:, :, :, 3], my_array[:, :, 2, …

Total answers: 2

Convert column to Numpy within a select statement in Polars

Convert column to Numpy within a select statement in Polars Question: I am trying to transform a date column to the next business day after each date (if the date isn’t already a business day in which case it remains unchanged). To do this I am using a Numpy function called busday_offset which takes a …

Total answers: 1

Assignment of matrix through nested loops only works for first row

Assignment of matrix through nested loops only works for first row Question: See the following simplified code import numpy as np u=np.zeros((3,3)) i,j=0,0 while i<3: while j<3: u[i,j]=i+j j=j+1 i=i+1 I was expecting a full matrix u (except for [0,0] element). This code seems to assign to only first row of u. I have used …

Total answers: 2

How to insert data in a numpy array, preserving its shape?

How to insert data in a numpy array, preserving its shape? Question: I have a collection of several data of fixed shape, and I need to store these values in an array, only creating a new dimension, so I can preserve its initial shape. Here is a small example, arr = np.array([0,1,2]) values = np.array([[3,4,5], …

Total answers: 2

why is numpy prod not working as intended?

why is numpy prod not working as intended? Question: I have a list with n elements and I need to know the product between them all, so: [x1, x2, x3, …] and I need the result of x1 * x2 * x3 … So i tried the numpy funcion prod as follows: np.array([20, 19, 18, …

Total answers: 2

Identifying ones in each row and creating a list in Python

Identifying ones in each row and creating a list in Python Question: I have an array A. I am identifying ones in each row except the row number itself and creating a list. For example, in A[0], the ones should be identified for locations 2,3,5 and not 0. I present the current and expected output. …

Total answers: 2

np.concatenate dimension problem of 1 & 3 channel image input

np.concatenate dimension problem of 1 & 3 channel image input Question: I’m trying to train a future 7days broccoli Unet model I try to concatenate images, because my input have 8 channel(51channel 13channel[index 5]) appear this error message img_batch = np.concatenate(images, axis=3)________line172 mask_batch = np.concatenate(masks, axis=2)________line173 y_int = np.argmax(mask_batch, axis=2) y_binary = to_categorical(y_int) yield (img_batch, …

Total answers: 1

How to count number of consecutive Trues in a numpy array along a given axis?

How to count number of consecutive Trues in a numpy array along a given axis? Question: I have for example the following np array array([[ True, False, False], [False, True, True], [ True, True, True], [False, True, True], [False, True, True], [ True, False, False], [ True, True, False], [False, False, True]]) I want to …

Total answers: 2