shapes

How to use cupy.lib.stride_tricks.as_strided(x, shape=None, strides=None)

How to use cupy.lib.stride_tricks.as_strided(x, shape=None, strides=None) Question: I was using: np.lib.stride_tricks.sliding_window_view with a 1D-array and two parameters (the array and the length of the subset n) to slice it into slices of n elements (n < 1D-array.shape, of course) I think I can go faster with cupy and I started with: cupy.lib.stride_tricks.as_strided(x, shape=None, strides=None) Documentation …

Total answers: 2

How to solve the shapes of model are incompatible?

How to solve the shapes of model are incompatible? Question: This is my train & test split shape: print(X_train.shape) print(X_test.shape) print(y_train.shape) print(y_test.shape) ———————- (120000, 72) (12000, 72) (120000, 6) (12000, 6) I reshape the data for CNN: X_train = X_train.reshape(len(X_train), X_train.shape[1], 1) X_test = X_test.reshape(len(X_test), X_test.shape[1], 1) X_train.shape, X_test.shape ——————————————————————- ((120000, 72, 1), (12000, 72, …

Total answers: 1

Create a vector length n with n entries 'x'

Create a vector length n with n entries 'x' Question: Example: n = 5 x = 3.5 Output: array([3.5, 3.5, 3.5, 3.5, 3.5]) My code: import numpy as np def init_all_x(n, x): np.all = [x]*n return np.all init_all_x(5, 3.5) My question: Why init_all_x(5, 3.5).shape cannot run? If my code is wrong, what is the correct …

Total answers: 4

How to make lists equal a quadrilateral in Python?

How to make lists equal a quadrilateral in Python? Question: I am having difficulty figuring out to make user-entered lists of numbers equal a quadrilateral, specifically a rhombus and square, in Python. I do not know if my code needs a function or loops or if/else statements to know if it is a rhombus or …

Total answers: 2

How to generate a ripple shape pattern using python

How to generate a ripple shape pattern using python Question: I am looking to create a repetitive pattern from a single shape (in the example below, the starting shape would be the smallest centre star) using Python. The pattern would look something like this: To give context, I am working on a project that uses …

Total answers: 2

Concatenate tensors with different shapes in tensorflow

Concatenate tensors with different shapes in tensorflow Question: I am new to tensorflow and I’m trying to concatenate 2 tensors with different shapes. The tensors have shape: >>> a # <tf.Tensor: id=38, shape=(30000, 943, 1), dtype=float64 >>> b <tf.Tensor: id=2, shape=(30000, 260, 1), dtype=float64 Is it possible to concatenate them on axis=0 to obtain a …

Total answers: 2

PyTorch: How to multiply via broadcasting of two tensors with different shapes

PyTorch: How to multiply via broadcasting of two tensors with different shapes Question: I have the following two PyTorch tensors A and B. A = torch.tensor(np.array([40, 42, 38]), dtype = torch.float64) tensor([40., 42., 38.], dtype=torch.float64) B = torch.tensor(np.array([[[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]], [[4,5,6,7,8],[4,5,6,7,8],[4,5,6,7,8],[4,5,6,7,8],[4,5,6,7,8]], [[7,8,9,10,11],[7,8,9,10,11],[7,8,9,10,11],[7,8,9,10,11],[7,8,9,10,11]]]), dtype = torch.float64) tensor([[[ 1., 2., 3., 4., 5.], [ 1., 2., 3., 4., 5.], …

Total answers: 1

Shape Openness detection in OpenCV

Shape Openness detection in OpenCV Question: I’m building a shape analysis algorithm and one of the attributes we would like to add is whether the shape is open or closed. For example, the left circle is closed, the middle circle is open and the right circle is more open. I tried to do it via …

Total answers: 2