Questions tagged [tensor]

A tensor is a multi-dimensional array. It is a key entity in many computational libraries, such as tensorflow, torch, theano, caffe, mxnet, used for machine learning tasks. If you use this tag, also tag the question with the corresponding library.

Filter by
Sorted by
Tagged with
0 votes
1 answer
27 views

Efficient Way to Find Indices of Unique Rows in PyTorch Tensor

I am working in PyTorch and I trying to find the index of the first occurrence of each unique row. Here's what I have so far: import torch import numpy as np # Example tensor data = torch.rand(100, 5)...
ogledala's user avatar
  • 117
0 votes
0 answers
7 views

Symbolic Tensor Assignment of Floats from Tensor Path

I am attempting to implement a neural network in tensorflow 2.14 which uses the name of the image to collect 5 float32 label values. I am using the dataset.map function similar to tf.data flowers ...
Daniel Sills's user avatar
1 vote
2 answers
24 views

Torch Tensor flatten, pad and unflatten again

I have a torch.tensor with dimensions (2, 3): 1 2 3 4 5 6 I want to create tensor with dimensions (2, 5) like this: 1 2 3 4 5 6 0 0 0 0 How do I can do this effectively? Also for backward transform.
Ars ML's user avatar
  • 89
-1 votes
1 answer
21 views

Add 4D tensor of shape (16, 8, 8, 5) and 2D tensor of shape (16, 16)

I want to add a noise of shape (16,16) to a 4D tensor of shape (16,8,8,5). I have tried several broadcasting approaches but still get errors but I get singleton mismatch errors. How can I add these ...
danny's user avatar
  • 1
0 votes
1 answer
20 views

Print intermediate gradient values during backward pass in Pytorch using hooks

I am trying to print the value of each of the intermediate gradients during backward pass of a model, using register backward hooks: class func_NN(torch.nn.Module): def __init__(self,) : ...
Newbie's user avatar
  • 1
0 votes
0 answers
42 views

Pytorch RunTimeError: one of the variables needed for gradient computation has been modified by an inplace operation

I am currently working on a project that involves the implementation of Bayesian GAN. I am following the Pytorch implementation, and this seems to follow the style of the official tutorial of DCGAN. ...
Preetom Saha Arko's user avatar
0 votes
0 answers
13 views

KerasTensor to Tensor

I am working on a image classification problem using a transformer model with linear self-attention. I get a type error stating: "TypeError: linear(): argument 'input' (position 1) must be Tensor,...
Deandre Way's user avatar
0 votes
1 answer
26 views

Error With Pytorch: "RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x150528 and 784x512)"

I am trying to train a model by Pytorch. The data set belongs to me and it has 2 folders: train_data and test_data. And every folder has 2 folders: detected and not_detected (these are my classes). ...
Baguviks's user avatar
0 votes
1 answer
19 views

How to utilize the sparsity of tensor?

For dense matrix contain lots of zeros, scipy.sparse implement sparse matrix to store and manipulate it efficiently. But if a tensor (higher than 2-D) is sparse, we can also utilize the sparsity, are ...
zjsun's user avatar
  • 31
1 vote
1 answer
69 views

Tensor (5-dim matrix) in python pandas?

I have a CSV file that looks like time Col_A Col_B Col_C Col_D Price 123 A1 B1 C2 D6 23.43 124 A5 B3 C7 D1 14.63 125 A3 B2 C3 D2 343.43 126 A2 B1 C2 D6 43.43 127 A1 B1 C7 D2 6.63 Now I want to ...
Orvar Korvar's user avatar
-1 votes
0 answers
16 views

Modifying ml tutorial code from google does not give expected result

There is a nice mini example for ml python code using tensorflow lib. Tutorial at google code labs It's (correctly) predicting a number from a linear equation. But just making a small mod to have the ...
Gert Gottschalk's user avatar
0 votes
1 answer
29 views

How are dimensions handled in pytorch's tensors?

How does the size parameter behave in creation of tensors? How does the axis parameter behave in methods like torch.Tensor.sum() and torch.Tensor.softmax()? I would like to give a good overview of how ...
Lukas's user avatar
  • 426
0 votes
1 answer
28 views

Pytorch split Tensor when consecutive zeros

I am attempting to segment a 1D pytorch tensor each time when a sequence of x consecutive zeros is encountered. If additional zero elements follow this 'split,' I intend to remove them until the next ...
Relluuuu's user avatar
0 votes
0 answers
48 views

error for tensor size speecht5 model-Sizes of tensors must match except in dimension 2. Expected size 16 but got size 256 for tensor number 1

18 frames /usr/local/lib/python3.10/dist-packages/transformers/models/speecht5/modeling_speecht5.py in forward(self, input_values, speaker_embeddings) 700 speaker_embeddings = ...
xerox fidley's user avatar
0 votes
0 answers
28 views

Nevertheless input different 'data.csv' |Why RNN result's always linear?

It's my forecast code import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler from tensorflow.keras.models import Sequential from ...
tuk_shin19's user avatar
0 votes
0 answers
18 views

Input tensor is not an XLA tensor: CPUFloatType

RuntimeError: torch_xla/csrc/aten_xla_bridge.cpp:73 : Check failed: xtensor *** Begin stack trace *** tsl::CurrentStackTrace() torch_xla::bridge::GetXlaTensor(at::Tensor const&) ...
defacto_deepak's user avatar
0 votes
0 answers
26 views

When I convert data between tensor of Pytorch and numpy, when do they share memory and when do they use new memory?

I write two pieces of programm. The first is: import torch c = torch.ones(3, 3) d = c.numpy() e = torch.tensor(d) e[0, 0] = 100.0 print(c) print(d) output is: tensor([[1., 1., 1.], [1., 1., ...
Frankenstein's user avatar
0 votes
0 answers
18 views

How to process a tensor without using a for loop?

tensor = torch.zeros_like(out, dtype=torch.int).to(out.device) for b in range(out.shape[0]): for index in range(out.shape[1]): n = numbers[b,index] tensor[b,index,...
kaisheng luo's user avatar
0 votes
0 answers
10 views

How do I add a channel token embedding in vision Transformer TensorFlow?

I am trying to create a specific version of a Vision Transformer, where patch tokens are generated for each individual channel, utilizing a learnable channel embedding chn to preserve channel-specific ...
tenikola's user avatar
0 votes
1 answer
33 views

How to convert a tensor scalar to a tensor list without detach it

I have a tenor.long scalar named x. how can I make a list of tensor tensor[(x.detached().numpy())] without converting x to numpy
Tommy  Yu's user avatar
  • 1,084
0 votes
0 answers
18 views

Dealing with dims and indexing NaN's in pytensor/PYMC

I am currently engaged in a spline regression task in pymc and have been grappling with a particular issue for some time. Consider the code below: import numpy as np import pymc as pm import ...
spline regressor's user avatar
-1 votes
1 answer
31 views

InvalidArgumentError: `predictions` contains negative values

I was trying to run the Tensorflow Audio classification code following the article of tensorflow. When I ran the following python code after finishing all above cells orderly: Code: confusion_mtx = ...
Sazzad Hissain Khan's user avatar
0 votes
0 answers
34 views

Too many theano runtime errors

I created a conda envirinment with python 3.9 and Installed theano 1.0.5. But when I write this simple program, I encounter many errors. This is my code: import theano from theano import tensor as T ...
amirabbas Gheisary's user avatar
0 votes
0 answers
15 views

Predicting column vector from SPD matrices

I am trying to predict a patient's fluxes which is a [24x29] matrix. I have this data set of 1802 patient's fluxes which I then transformed all of them to a Symmetric Positive Definite (SPD) matrix of ...
meatball2000's user avatar
0 votes
1 answer
21 views

How to aggregate a pytorch tensor to a smaller size?

I'm new to pytorch and tensors and I'm wondering how to do the following. I'll explain with a super simple example: If I have a 1d tensor of 9 values - [1,2,3,4,5,6,7,8,9] I'd like to "aggregate&...
Pfunk's user avatar
  • 11
-1 votes
0 answers
21 views

How to convert tf.data.Datasets to a tensor

I am writing a custom_loss function wherein I'm trying to use data other than y_true and y_pred. The data is in the form of tensorflow Dataset. How can it be converted to tensors to form the ...
Nadiyah Ahmed's user avatar
0 votes
0 answers
10 views

Why this triton kernel crashes?

I can't find what is the error in this code, it suppose to merge p tensors of size (n, k) such that the merged tensor of size (n, k) has alternating element of these p tensors without doublon per row. ...
Didier's user avatar
  • 11
0 votes
1 answer
51 views

Is it possible to recursively chip an Eigen Tensor based on the values specified in an array?

I am trying to create a wrapper around an Eigen::Tensor object in c++. The idea is to create a chipped view on a Tensor based on a provided array, which either specifies the row along which to chip or ...
Yes's user avatar
  • 331
0 votes
0 answers
15 views

Issue with leaf tensor error during backprop

import torch import torch.nn.functional as F weights = [] bias = [] z = [] act = [] lr = 0.01 shapes = [6, 400, 400, 400, 2] x = [[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0],[0,0,0,1,0,0],[0,0,0,0,1,0],[...
Amr Tamer's user avatar
0 votes
0 answers
41 views

How to create tensor from a csv file in onnx runtime?

I've trained a CNN model on python, and saved it as an onnx model. Now I want to use it in a c# winforms application, to perform inference on .csv files. I read that one should use a onnx runtime for ...
mtm's user avatar
  • 1
0 votes
1 answer
32 views

Pyhton extract matrices from rank 3 tensor

I have data X_train with shape (19601, 1000, 12) but want to extract the 1000 x 12 matrices and combine/append them into one large matrix. Whenever I try to index through X_train and append the rows ...
stone327's user avatar
0 votes
0 answers
5 views

Where can I get FDMA Competition dataset?

I am working on malicious activity detection and am searching for the FDMA 2012 competition dataset. I have encountered difficulty accessing it, as SMU, which originally organized the competition, has ...
sindhuja's user avatar
  • 167
1 vote
0 answers
23 views

how to split a tiled pytorch tensor into a bunch of little tensors?

I have a pytorch tensor that I have tiled so it looks like a matrix of lots of little matrices. I would like to split it into a list of lists of those matrixes as I have additional info that I need ...
Christopher Clark's user avatar
1 vote
1 answer
68 views

Pytorch uint8 tensor indexing

I am trying to slice signal_matrix by in_inds, but uint8 indexing is a different i guess. Can someone explain how it suppose to work? signal_matrix = torch.tensor( [[0, 0, 1, 1],...
Nobilis Manius's user avatar
1 vote
1 answer
45 views

Smooth clamping a tensor

Is there a simpler and more performant way to do this? Can it be done for each channel individually instead of having a global max/min, in a single operation? Essentially "soft clamping" ...
Timothy Alexis Vass's user avatar
1 vote
1 answer
42 views

Converting from list of very small floats to a PyTorch tensor gives a TypeError because PyTorch interprets scientific notation as str instead of float

I have data that I want to setup as a PyTorch tensor as my objective for a ML algorithm. If I inspect the list as is I get : ydata = [1.39e-11, 1.5e-12, 4.7e-16] I want to have this list in a tensor, ...
TonyR's user avatar
  • 59
-1 votes
1 answer
128 views

Tensorflow : could not a find a version that satisfies the requirement tensorflow

I am try to install tensorflow through pip but it showing error "could not a find a version that satisfies the requirement tensorflow" Python 3.12.0 pip 23.3.1 i tried this cmd: python3 -m ...
shashwat choudhary's user avatar
0 votes
0 answers
66 views

The expanded size of the tensor (1536) must match the existing size (512) at non-singleton dimension 1

I'm trying to train my BERT model for sentences binary classification task (Inputs are 2 sentences and output label: 1 not similar and 0 for not similar). The problem arises when I trained my model, ...
A Random Guy's user avatar
1 vote
1 answer
114 views

What are the aims for the Apache Arrow Tensor Extension types?

Apache Arrow (Columnar Format) is a "standard and efficient in-memory representation of various datatypes". DLPack is an "open in-memory tensor structure for sharing tensors among ...
nenb's user avatar
  • 75
0 votes
1 answer
14 views

How to convert PyTorch tensor dimension?

I have tensor with dimension (210,2) using PyTorch. I want to convert it into (15,14,2). Anyone know how to do this? Thank you in advance
ryan chandra's user avatar
0 votes
1 answer
73 views

using TensorFlow Model in Spring for inference/predictions - Kotlin

I'm trying to find a way to use tensorflowmodel in Spring Boot, I loaded the model successfully, and created the needed tensor, but I can't make a call to get the result from the model because of this ...
Saher Al-Sous's user avatar
1 vote
1 answer
32 views

find symbolic tensor elements in another tensor one by one

I have a model def apk(x: SymbolicTensor, y: SymbolicTensor, k=10): """ Computes the average precision at k. """ #here I need to find number of elements x, ...
Anton Anisimov's user avatar
3 votes
2 answers
122 views

What is the best way to obtain every slice sums in tensor in Julia?

T is a given tensor. I need the slice sums of T in every direction. For example, for a 4-order tensor T, I wrote the following code. function get_every_slice_sums(T) A = sum(T, dims=[ 2,3,4]) B ...
Sakurai.JJ's user avatar
1 vote
1 answer
97 views

How do I get Eigen::TensorRef to work for broadcast and other operations?

I'm using Eigen 3.4 with MSVC. I have used Eigen::Ref before, with some success, and I am trying to use Eigen::TensorRef, but am running into issues: Eigen::Tensor<double, 3> A(3, 1, 2); A....
Danny's user avatar
  • 356
1 vote
2 answers
50 views

How are tensors of different shapes combined?

In what logic are multidimensional tensors (e.g. in pytorch) combined? Let's say I have tensor A with shape (64, 1, 1, 42) and tensor B with shape (1, 42, 42). What is the result of A & B and how ...
bearyTheBear's user avatar
0 votes
1 answer
51 views

Decompose np.einsum into np.dot operations

I want to do a summation over a 4-D tensor and corresponding coefficients. One could use 4 nested for loops to get the right answer. But we all know that for loops are two slow in Python. Here I ...
youmu's user avatar
  • 1
-1 votes
1 answer
30 views

Tensor Networks for Machine Learning, mnist classification

I am dealing with a tensor network for ML task. Explicitly for classifying MNIST dataset of handwritten digits, each image consists of N = 28 × 28 = 784 pixels. But the methodology and implementation ...
Mayssa's user avatar
  • 1
1 vote
1 answer
194 views

SentenceTransformer Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory

I'm using google colab to try this and I download the model for sentenceTransformers from huggingface hub using snapshot_download. For the model I'm using all-MiniLM-L6-v2 When I load the model from ...
Abstract's user avatar
0 votes
0 answers
13 views

Error while defining a string variable in tf.data.experimental.CsvDataset

I build my dataset (ds) using this fonction: def build_dataset(path_list, index_variables_retenus, header=True, field_delim=','): def csv_loader(path): return tf.data.experimental....
Jonathan Roy's user avatar
5 votes
1 answer
133 views

Converting a pandas dataframe to a pytorch tensor

I am trying to convert a pandas dataframe read from a CSV file to a pytorch tensor, but am getting a type error. I tried doing this: df = pandas.DataFrame({"spam": [1, 2, 3, 4], "...
Yoogi Kovendhan's user avatar

1
2 3 4 5
57