Python 为什么';示例(U尺寸' ;;can';在代码中找不到?
输出为Python 为什么';示例(U尺寸' ;;can';在代码中找不到?,python,numpy,shuffle,Python,Numpy,Shuffle,输出为None 有谁能告诉我出了什么问题吗?问题是np.random.shuffle会在适当的位置修改序列。从: 通过洗牌内容就地修改序列 只需打印示例: import numpy as np def data_iter_random(data_indices, num_steps, batch_size): example_size = len(data_indices)/num_steps epoch_size = example_size/batch_size
None
有谁能告诉我出了什么问题吗?问题是
np.random.shuffle
会在适当的位置修改序列。从:
通过洗牌内容就地修改序列
只需打印示例
:
import numpy as np
def data_iter_random(data_indices, num_steps, batch_size):
example_size = len(data_indices)/num_steps
epoch_size = example_size/batch_size
example = [data_indices[i*num_steps:i*num_steps + num_steps]
for i in range(int(example_size))]
shuffle_example = np.random.shuffle(example)
print(shuffle_example)
data_iter_random(list(range(30)), 5, 2)
输出
import numpy as np
def data_iter_random(data_indices, num_steps, batch_size):
example_size = len(data_indices) / num_steps
epoch_size = example_size / batch_size
example = [data_indices[i * num_steps:i * num_steps + num_steps]
for i in range(int(example_size))]
np.random.shuffle(example)
print(example)
data_iter_random(list(range(30)), 5, 2)
这是因为
np.random.shuffle
是一种“就地”方法
- 所以不需要分配
- 它到位了吗
- 文档说:“通过改变序列的内容来修改序列。”
[[25, 26, 27, 28, 29], [5, 6, 7, 8, 9], [0, 1, 2, 3, 4], [20, 21, 22, 23, 24], [15, 16, 17, 18, 19], [10, 11, 12, 13, 14]]
为了那些台词
完整代码:
np.random.shuffle(example)
print(example)
输出:
import numpy as np
def data_iter_random(data_indices, num_steps, batch_size):
example_size = len(data_indices)/num_steps
epoch_size = example_size/batch_size
example = [data_indices[i*num_steps:i*num_steps + num_steps]
for i in range(int(example_size))]
np.random.shuffle(example)
print(example)
data_iter_random(list(range(30)), 5, 2)
像这样的函数很少。标题可能需要更改,因为这太具体了
[[5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [25, 26, 27, 28, 29], [15, 16, 17, 18, 19], [0, 1, 2, 3, 4], [20, 21, 22, 23, 24]]