python - 将矩阵拆分为多个矩阵
问题描述
我有如下代码,我必须将矩阵拆分为 n 个子矩阵。
two_dim_array = [['. An algorithm is a set of unambiguous instructions that a mechanical computer can execute.'],
['. An algorithm is a set of unambiguous instructions that a mechanical computer can execute.'],
['[b]'],
['\xa0A complex algorithm is often built on top of other, simpler, algorithms. A simple example of an algorithm is the following (optimal for first player) recipe for play at\xa0'],
['tic-tac-toe'], [':'], ['[62]'], ['If someone has a "threat" (that is, two in a row), take the remaining square. Otherwise,'],
['if'], [' a move "forks" to create two threats at once, play that move. Otherwise,'], ['take'],
[' the center square if it is free. Otherwise,'], ['if'],
[' your opponent has played in a corner, take the opposite corner. Otherwise,'], ['take'],
[' an empty corner if one exists. Otherwise,'], ['take'], [' any empty square.'],
['Many AI algorithms are capable of learning from data; they can enhance themselves by learning new\xa0'],
['heuristics'],
['\xa0(strategies, or "rules of thumb", that have worked well in the past), or can themselves write other algorithms. Some of the "learners" described below, including Bayesian networks, decision trees, and nearest-neighbor, could theoretically, (given infinite data, time, and memory) learn to approximate any\xa0'],
['function'], [', including which combination of mathematical functions would best describe the world'],
['['], ['citation needed'], [']'], ['. These learners could therefore, derive all possible knowledge, by considering every possible hypothesis and matching them against the data. In practice, it is almost never possible to consider every possibility, because of the phenomenon of "'],
['combinatorial explosion'], ['", where the amount of time needed to solve a problem grows exponentially. Much of AI research involves figuring out how to identify and avoid considering broad range of possibilities that are unlikely to be beneficial.'],
['[63]'], ['[64]'], ['\xa0For example, when viewing a map and looking for the shortest driving route from\xa0'],
['Denver'], ['\xa0to\xa0'], ['New York'], ['\xa0in the East, one can in most cases skip looking at any path through\xa0'], ['San Francisco'],
['\xa0or other areas far to the West; thus, an AI wielding a pathfinding algorithm like\xa0'], ['A*']]
n = int(len(two_dim_array)/2)
print(n)
sub_mat = [lines for i in range(0, len(two_dim_array),n) for lines in two_dim_array[i:n] ]
print("Changed array:",sub_mat)
在这里,我试图分成两半,我只得到矩阵的前半部分。可以帮助打破这个矩阵。
解决方案
普通切片
n = len(two_dim_array)//2
one, two = two_dim_array[:n], two_dim_array[n:]
推荐阅读
- scala - 改进一段 scala/spark 代码以提高性能
- python - 使用 Neat Algorithm 打开 AI Gym 不适用于 Jupyter
- html - CSS:尝试在没有垂直平移的情况下旋转门
- python - 试图从 txt 文件中读取链接
- python - 如何通过 Kivy 打开其他应用程序
- python - python 版本 2 和版本 3 是如何组织的?brew卸载python@后出现问题,我想恢复/修复
- r - 从下拉菜单中选择时的 RSelenium 问题
- node.js - 错误:当我将 dist 文件夹发布到 Azure 应用服务时,请求失败,状态码为 404
- mysql - 我怎样才能提高 mariadb 的性能
- r - 为什么我的重复阶乘 aov 无法识别我的样本量?