V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  allenwuli  ›  全部回复第 3 页 / 共 4 页
回复总数  63
1  2  3  4  
2019-06-18 16:29:49 +08:00
回复了 allenwuli 创建的主题 优惠信息 天猫 618 活动,整点抢 xr,前 100 名打一折, 618 元。
整点抢,前一百名 618。我也是在天猫官方微博上看到的: https://weibointl.api.weibo.cn/share/76713577.html?weibo_id=4384522026270170
2019-06-17 17:21:01 +08:00
回复了 lyver 创建的主题 推广 哦~618 是么......干脆来个好物分享,顺便送几波礼品吧
分母
2019-06-05 09:42:52 +08:00
回复了 allenwuli 创建的主题 iPhone PDD 上的 iPhone 为何那么便宜?
@l33ch 这价格降的太快,真想剁手啊
2019-05-31 13:46:04 +08:00
回复了 allenwuli 创建的主题 算法 超大数据量排序算法
import os
import argparse


class FileSplitter(object):
BLOCK_FILENAME_FORMAT = 'block_{0}.dat'

def __init__(self, filename):
self.filename = filename
self.block_filenames = []

def write_block(self, data, block_number):
filename = self.BLOCK_FILENAME_FORMAT.format(block_number)
with open(filename, 'w') as file:
file.write(data)
self.block_filenames.append(filename)

def get_block_filenames(self):
return self.block_filenames

def split(self, block_size, sort_key=None):
i = 0
with open(self.filename) as file:
while True:
lines = file.readlines(block_size)

if not lines:
break

if sort_key is None:

lin = [int(aaa.split("\n")[0]) for aaa in lines]
lin.sort()
lines = [str(sss) + "\n" for sss in lin]
else:
lin = [int(aaa.split("\n")[0]) for aaa in lines]
lin.sort(key=sort_key)
lines = [str(sss) + "\n" for sss in lin]

self.write_block(''.join(lines), i)
i += 1

def cleanup(self):
map(lambda f: os.remove(f), self.block_filenames)


class NWayMerge(object):
def select(self, choices):
print(choices)
min_index = -1
min_str = None
for i in choices.keys():
if min_str is None or choices[i] < min_str:
min_index = i
min_str = choices[i]
print(min_index)
return min_index


class FilesArray(object):
def __init__(self, files):
self.files = files
self.empty = set()
self.num_buffers = len(files)
self.buffers = {i: None for i in range(self.num_buffers)}

def get_dict(self):
return {i: int(self.buffers[i].split("\n")[0]) for i in range(self.num_buffers) if i not in self.empty}

def refresh(self):
for i in range(self.num_buffers):
if self.buffers[i] is None and i not in self.empty:
self.buffers[i] = self.files[i].readline()
if self.buffers[i] == '':
self.empty.add(i)
self.files[i].close()
if len(self.empty) == self.num_buffers:
return False

return True

def unshift(self, index):
value = self.buffers[index]
self.buffers[index] = None

return value


class FileMerger(object):
def __init__(self, merge_strategy):
self.merge_strategy = merge_strategy

def merge(self, filenames, outfilename, buffer_size):
buffers = FilesArray(self.get_file_handles(filenames, buffer_size))
with open(outfilename, 'w', buffer_size) as outfile:
while buffers.refresh():
min_index = self.merge_strategy.select(buffers.get_dict())
outfile.write(buffers.unshift(min_index))

def get_file_handles(self, filenames, buffer_size):
files = {}

for i in range(len(filenames)):
files[i] = open(filenames[i], 'r', buffer_size)

return files


class ExternalSort(object):
def __init__(self, block_size):
self.block_size = block_size

def sort(self, filename, sort_key=None):
num_blocks = self.get_number_blocks(filename, self.block_size)
splitter = FileSplitter(filename)
splitter.split(self.block_size, sort_key)

merger = FileMerger(NWayMerge())
buffer_size = self.block_size / (num_blocks + 1)
merger.merge(splitter.get_block_filenames(), filename + '.out', int(buffer_size))

splitter.cleanup()

def get_number_blocks(self, filename, block_size):
return (os.stat(filename).st_size / block_size) + 1


def parse_memory(string):
if string[-1].lower() == 'k':
return int(string[:-1]) * 1024
elif string[-1].lower() == 'm':
return int(string[:-1]) * 1024 * 1024
elif string[-1].lower() == 'g':
return int(string[:-1]) * 1024 * 1024 * 1024
else:
return int(string)


def main():

# parser = argparse.ArgumentParser()
# parser.add_argument('-m',
# '--mem',
# help='amount of memory to use for sorting',
# default='100M')
# parser.add_argument('filename',
# metavar='<filename>',
# nargs=1,
# help='name of file to sort')
# args = parser.parse_args()

sorter = ExternalSort(300)
sorter.sort('num1.txt')


if __name__ == '__main__':
main()
2019-05-27 14:29:43 +08:00
回复了 allenwuli 创建的主题 算法 超大数据量排序算法
@jmc891205 谢了老板
2019-05-16 17:11:04 +08:00
回复了 allenwuli 创建的主题 macOS macOS Mojave 10.14.5(18F132)卡顿
@cocoking 没有,使用 chrome 刷网页的时候,还是会不时的卡一下。
2019-05-16 11:36:47 +08:00
回复了 allenwuli 创建的主题 macOS macOS Mojave 10.14.5(18F132)卡顿
@cdlixucd 不知道啊,早知道不升级了。
2019-05-07 09:50:19 +08:00
回复了 allenwuli 创建的主题 机器学习 kmeans 算法,距离改用余弦相似度, Python 实现。
@SleipniR 大佬,我看了下这个算法
def euc_dist(x, y=None):
return cosine_similarity(x, y)
k_means_.euclidean_distances = euc_dist
这个算法在这步改成用余弦相似度。计算聚类中心是怎么计算的我点进源码也没看明白。能帮我解释一下他是如何计算类中心的吗?谢谢大佬
2019-05-06 14:44:06 +08:00
回复了 allenwuli 创建的主题 机器学习 kmeans 算法,距离改用余弦相似度, Python 实现。
@SleipniR 先谢谢大佬,我咋打不开链接呢。
你可以外包进
2019-04-08 17:45:23 +08:00
回复了 mv0x 创建的主题 问与答 我在北京租了一个大棚,你想种啥?
@dxgfalcongbit 你这只猫很漂亮
2019-03-04 11:35:52 +08:00
回复了 allenwuli 创建的主题 优惠信息 小米影视会员,便宜的渠道?
@zizifu 你从哪里买的啊?官网太贵了
2019-02-26 10:16:28 +08:00
回复了 allenwuli 创建的主题 优惠信息 小米影视会员,便宜的渠道?
@chiu 是的,现在还有么?
2019-01-29 09:34:47 +08:00
回复了 allenwuli 创建的主题 iPhone iphoneX 和 iPhonexr 该怎么选?
@milesnihao 在哪买的这便宜。我看苏宁最低也要 5288
1  2  3  4  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2675 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 44ms · UTC 05:42 · PVG 13:42 · LAX 21:42 · JFK 00:42
Developed with CodeLauncher
♥ Do have faith in what you're doing.