Troubles With For Loop, .append, Np.asarray
From an excelsheet, I import various columns and I write:
import numpy as np totaloutput =  inputdata = np.stack(various columns) for "number of variables in columns" in inputdata: calculate several numpy.ndarray-type arrays output = np.column_stack(several numpy.ndarray-type arrays) totaloutput.append(output)
When I print
totaloutput, I get:
[array([['0.8', '4.0', '0.5', '5.0', 'X','Y', '16.0', '345.0', '285.0', '0.5843940254127079', '0.3583943421752271'], ['0.8', '4.0', '0.5', '5.0', 'X','Y', '17.0', '345.0', '285.0', '0.36329780170652354', '0.22314099222162737'], [etc], [etc]],dtype='<U32'), array([['1.2', '4.0', '0.5', '5.0', 'X', 'Y', '16.0', '345.0', '15.0', '0.787996644827825', '0.48299132454894594'], [etc], [etc]],dtype='<U32'),
The type of the output according to
type(totaloutput) is a
list. However, to be able to export the data, I have to manage to get the data in the following shape:
[['0.800000011920929' '3.5' '1.0' '4.0' 'X', 'Y', '15.0' '345.0' '285.0' '0.6222837267695641' '0.37663730483688007'] ['0.800000011920929' '3.5' '1.0' '4.0' 'X', 'Y', '15.0' '345.0' '285.0' '1.4079677072051757' '0.8500865690052523'][etc][etc]]
I thought I solved it by saying:
totaloutput = np.asarray(totaloutput) totaloutput = np.reshape((totaloutput, ((len(inputdata)),11))
Whenever I extend the amount of
inputdata (which is the goal of the script, to automatically calculate for a large amount of data),
np.asarray does not seem to work anymore. I've found someone having problems with this too.
I can confirm this by printing
np.asarray(totaloutput) and afterwards and state that both prints are the same. (the unwished array=...dtype thing) The weird thing is, when after
np.asarray(totaloutput) I print the
type, it does says
With a smaller
np.asarray(totaloutput), it generates a neat
I've tried lots of other ways to get a right output, I've seen that
for i in range(len(inputdata)): print(totaloutput.item(i))
Is exactly what I need, but whenever I try:
for i in range(len(inputdata)): finaloutput = (totaloutput.item(i))
totaloutput = (totaloutput.item(i))
AttributeError: 'str' object has no attribute 'item'
I am assuming your problem is you have list of numpy array, you want to stack it into one list?
If it is correct. Have tried
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module