我真的需要你的帮助。我一直试图转换它并寻找文档,但我想我并不确切知道我在寻找什么。
我的输入文件具有以下结构:
20010102,2301,0.95070,0.95070,0.95070,0.95070,4
20010102,2302,0.95060,0.95060,0.95050,0.95050,4
20010102,2303,0.95050,0.95070,0.95050,0.95060,4
20010102,2304,0.95060,0.95060,0.95060,0.95060,4
这是我的代码:
import numpy as np
EU = np.loadtxt('data_s.csv', delimiter=',')
sample = EU[:5]
size = len(sample)
print (sample)
输出就是:
[[ 2.00101020e+07 2.30100000e+03 9.50700000e-01 9.50700000e-01
9.50700000e-01 9.50700000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30200000e+03 9.50600000e-01 9.50600000e-01
9.50500000e-01 9.50500000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30300000e+03 9.50500000e-01 9.50700000e-01
9.50500000e-01 9.50600000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30400000e+03 9.50600000e-01 9.50600000e-01
9.50600000e-01 9.50600000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30500000e+03 9.50600000e-01 9.50600000e-01
9.50600000e-01 9.50600000e-01 4.00000000e+00]]
所以我尝试重塑它(我肯定不是我应该做的):
sample = sample.reshape(size, 7)
print(sample)
我的输出完全相同:
[[ 2.00101020e+07 2.30100000e+03 9.50700000e-01 9.50700000e-01
9.50700000e-01 9.50700000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30200000e+03 9.50600000e-01 9.50600000e-01
9.50500000e-01 9.50500000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30300000e+03 9.50500000e-01 9.50700000e-01
9.50500000e-01 9.50600000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30400000e+03 9.50600000e-01 9.50600000e-01
9.50600000e-01 9.50600000e-01 4.00000000e+00]
[ 2.00101020e+07 2.30500000e+03 9.50600000e-01 9.50600000e-01
9.50600000e-01 9.50600000e-01 4.00000000e+00]]
我正在寻找的是这样的输出:
[[[2.00101020e+07], [2.30100000e+03], [9.50700000e-01], [9.50700000e-01],
[9.50700000e-01], [9.50700000e-01], [4.00000000e+00]],
...]
我也试过这个:
sample = EU[:5]
final = []
for line in sample:
va = []
for var in line:
var = np.array(var)
va.append(var)
final.append(va)
print(final)
,输出结果为:
[[array(20010102.0), array(2301.0), array(0.9507), array(0.9507), array(0.9507), array(0.9507), array(4.0)], [array(20010102.0), array(2302.0), array(0.9506), array(0.9506), array(0.9505), array(0.9505), array(4.0)], [array(20010102.0), array(2303.0), array(0.9505), array(0.9507), array(0.9505), array(0.9506), array(4.0)], [array(20010102.0), array(2304.0), array(0.9506), array(0.9506), array(0.9506), array(0.9506), array(4.0)], [array(20010102.0), array(2305.0), array(0.9506), array(0.9506), array(0.9506), array(0.9506), array(4.0)]]
恰好是一个列表,而不是一个数组。所以我试过这个:
final = np.array(final)
这让我回到了起点。
我正在开发一个能够接受这些输入的机器学习项目,目前它们看起来每条线都是输入,没有什么比这些值更像是一个单独的变量。
也许我在想这个错误。我尝试使用熊猫,但我意识到使用numpy并经历必须解决这个问题的痛苦比让pandas给我几千兆字节的数据几乎可以达到几百MB更好。
这可能很傻但请帮助我!我将非常感谢你的帮助!
答案 0 :(得分:0)
你试过吗
{% extends 'base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link type="text/css" rel="stylesheet" href="{{ asset('js/plupload/jquery-ui-1.12.1/jquery-ui.css') }}" />
<link type="text/css" rel="stylesheet" href="{{ asset('js/plupload/jquery.ui.plupload/css/jquery.ui.plupload.css') }}" media="screen" />
{% endblock %}
{% block content %}
<div id="box-upload">
<div id="uploader">
<p>Your browser doesn't have HTML5 support.</p>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script type="text/javascript" src="{{ asset('js/browserplus/browserplus.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/jquery-2.2.4.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/plupload/jquery-ui-1.12.1/jquery-ui.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/plupload/jquery.ui.plupload/jquery.ui.plupload.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/plupload/i18n/lv.js') }}"></script>
<script type="text/javascript">
'use strict';
$(function()
{
var uploader;
uploader = $("#uploader");
uploader.plupload(
{
// General settings
runtimes: 'html5',
url: "{{ oneup_uploader_endpoint('gallery') }}",
multi_selection: true,
// Maximum file size
max_file_size: '5mb',
chunk_size: '5mb',
// Specify what files to browse for
filters: [
{title: "Image files", extensions: "jpg,jpeg,png,gif"},
{title: "Zip files", extensions: "zip,7z"},
{title: "Pdf files", extensions: "pdf"},
{title: "Binary files", extensions: "bin"},
{title: "Text files", extensions: "txt"},
{title: "Media files", extensions: "avi"}
],
// Rename files by clicking on their titles
rename: true,
// Sort files
sortable: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
// Views to activate
views: {
list: true,
thumbs: false, // Show thumbs
active: 'list'
}
});
var $uploader = uploader.plupload('getUploader');
// Add Clear Button
var $button = $("<button>"+ plupload.translate("Clear list") + "</button>").button({icons: {primary: "ui-icon-trash"}}).button("disable").appendTo('.plupload_buttons');
// Clear Button Action
$button.click(function()
{
removeErrorMessages();
$uploader.splice();
$(".plupload_filelist_content").html('');
$button.button("disable");
return true;
});
// Clear Button Toggle Enabled
$uploader.bind('QueueChanged', function ()
{
if ($uploader.files.length > 0)
{
$button.button("enable");
}
else
{
$button.button("disable");
}
});
// Clear Button Toggle Hidden
$uploader.bind('StateChanged', function ()
{
if ($uploader.state == plupload.STARTED)
{
$button.hide();
}
else
{
$button.show();
}
});
// Clear Button Toggle Hidden
$uploader.bind('Browse', function ()
{
removeErrorMessages();
$uploader.splice();
});
$uploader.bind('Error', function(uploader, error)
{
console.error(error.message);
console.log(error.message);
});
function removeErrorMessages()
{
$(".ui-state-error").remove();
}
});
</script>
{% endblock %}