Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Ruby中使用四舍五入对数组进行切片_Ruby_Arrays_Slice - Fatal编程技术网

在Ruby中使用四舍五入对数组进行切片

在Ruby中使用四舍五入对数组进行切片,ruby,arrays,slice,Ruby,Arrays,Slice,有人能帮我把这个“伪代码”转换成Ruby吗 你想把所有的东西都集中起来 # Slices of 100 elements each physical_values.each_slice(100){ |part| send_part_to_server( part ) } # <=100 slices slice_size = (physical_values.length.to_f/100).ceil physical_values.each_slice(slice_size){ |pa

有人能帮我把这个“伪代码”转换成Ruby吗

你想把所有的东西都集中起来

# Slices of 100 elements each
physical_values.each_slice(100){ |part| send_part_to_server( part ) }

# <=100 slices
slice_size = (physical_values.length.to_f/100).ceil
physical_values.each_slice(slice_size){ |part| send_part_to_server( part ) }

你能提供物理_值的样本数据吗?你能解释一下这段代码应该做什么吗?这是一个包含5000条数据记录的数组,我需要将这个数组拆分为每个“chunck”的100个元素并发送到服务器。将来,请在描述你意图的地方提问,并提供样本输入和输出。欢迎使用Ruby和Stack Overflow!:)对不起!我也是堆栈溢出的初学者:)非常感谢你的帮助!
11.05016861219201 10.350157930876776 10.550160982681064 11.550176241702957 12.55019150072485 12.750194552529138 11.850180819409616 10.350157930876776 9.15013962005014 9.15013962005014 10.450159456778692 12.15018539711582 13.250202182040084 12.95019760433388 11.750179293507244 10.65016250858298 10.850165560387723
# Slices of 100 elements each
physical_values.each_slice(100){ |part| send_part_to_server( part ) }

# <=100 slices
slice_size = (physical_values.length.to_f/100).ceil
physical_values.each_slice(slice_size){ |part| send_part_to_server( part ) }
(physical_values.length/100.0).ceil # Use a floating point 100.0 for float result