Transfrom tensor to array

shangguan91: <p>Data(face=[3, 43517], pos=[43812, 3])<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/8/2806112da81cf826086dfaf09d41a28f35420802.png" data-download-href="https://discuss.pytorch.org/uploads/default/2806112da81cf826086dfaf09d41a28f35420802" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/8/2806112da81cf826086dfaf09d41a28f35420802.png" alt="image" data-base62-sha1="5I462Tb5DeYXikjZIYVZ1wQkv4K" width="690" height="211" data-dominant-color="F3F3F3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">704×216 5.94 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/5/b/5bc719b8f8d7bc86adc9152173b3a2981987fec5.png" alt="image" data-base62-sha1="d5U1hg7xIN1kLKlQokJadL4MNsp" width="382" height="162"></p>
<p>how could transfrom this data</p>

ptrblck: <p>What kind of transformation would you like to use?<br>
It seems you are dealing with some kind of features or coordinates?</p>

shangguan91: <p>i am dealing with mesh data,  i have done first step by use .numpy.</p>
<p>Now, i need to reshape data into following form.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/5/7/57cb302852d0163f5cae0205283eff2aff063fe6.png" alt="image" data-base62-sha1="cwERQlWuExVoa0pJsrPAsZq0PFI" width="546" height="448"></p>
<p>this is my data, it is really similar to the data in pretrained model.  however, it has no shape and look like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/9/39e6dd9c28efdc1c1f7080aea57e0917c9777f7f.png" data-download-href="https://discuss.pytorch.org/uploads/default/39e6dd9c28efdc1c1f7080aea57e0917c9777f7f" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/9/39e6dd9c28efdc1c1f7080aea57e0917c9777f7f.png" alt="image" data-base62-sha1="8gdQhkQRPF9rSsNKnryGAzFv1pR" width="690" height="437" data-dominant-color="F8F7F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">862×547 16.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
how could i reshape into (a,b,c)shape</p>

shangguan91: <p>i just check the datatype, i want to reshape this turple into ndarray, the single array in my data is the array in pretrained model</p>

ptrblck: <p>Since <code>d</code> is a <code>tuple</code>, you could index it and get the shapes of all internal arrays via:</p>
<pre><code class="lang-python">for tmp in d:
    print(tmp.shape)
</code></pre>
<p>Could you post these shapes, so that we can see how to reshape these arrays?</p>

shangguan91: <p>the shape of pretrained model: <img src="https://discuss.pytorch.org/uploads/default/original/3X/c/6/c6619a8086c90017169e8f72a3d08a11ea2f5f74.png" alt="image" data-base62-sha1="siXEwX68qyQaVvQMFoCI8tmcu6E" width="441" height="305"><br>
Sorry, my data turns out to be list.<br>
it works with ur code as well, this my shape, each data have different numbers of clound points.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/0/6/06c71265256a89d9d4395576dd836ea8a4d36893.png" alt="image" data-base62-sha1="XXncPNN4XA8LNysNhmOUcRiOTV" width="549" height="432"></p>

shangguan91: <p><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/2/d2d5845e42e12f34be1a8d65a690d477680d157a.png" alt="image" data-base62-sha1="u57J4yI0TcyvxJHGV4KG5UvBcGm" width="687" height="486"></p>

ptrblck: <p><code>data</code> seems to be a numpy array, not a list, since <code>type(data)</code> returns <code>numpy.ndarray</code> and also <code>data.shape</code> seems to work, while it was raising an error before, so apparently something in the code has changed.</p>
<p>Anyway, <code>tmp</code> seems to have varying shapes, so you won’t be able to reshape it to e.g. a tensor with the shape <code>[2048, 2048, 3]</code>, but would need to interpolate, slice, etc. the tensors somehow.</p>
<p>Could you explain your use case a bit, i.e. why would you need to reshape all tensors to a particular shape and how this reshaping should be done, if the number of elements doesn’t match?</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

shangguan91: <p>hey, i do not need shape to shape exactly like <code>[2048, 2048, 3]</code> , However, i need to shape it to 3 dimension <code>[a, b, 3]</code> so that i can implement a graph-classifcation model<a href="https://github.com/aboulch/ConvPoint/blob/master/examples/modelnet/modelnet_classif.py" rel="nofollow noopener">https://github.com/aboulch/ConvPoint/blob/master/examples/modelnet/modelnet_classif.py</a>.</p>
<p>Forward pass of this model have (x, inputs_pts) which has form: input_pts.shape = [BatchSize, Dim, NPoints] and x.shape = [BatchSize, C, NPoints]</p>
<p>i was trying to load data exactly like pretrained model, so i can run this classfication without further concern. However, as shape varing for each single object. i do not know how to do it.</p>
<p>But here comes now a another solution: i have now data.pos with shape[Points.Dim] and x[C, Npoints], all i need to do is add to 3d dimension. Still i can not concatnate,of np.stock, cuz different dimension.</p>

shangguan91: <p><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/7/97df4f6c9424268660a3a82717a899d26e9500a4.png" alt="image" data-base62-sha1="lFwxmeIvjLvn6rAsvg3c1deezRO" width="676" height="496"> , i truely wish u could help me further, after transfrom my data, it become a list like this, if i do data[0].pos, it will have shape(2048,3). how do i turn all data to array then np.stack it</p>