The python range() function creates a list of integers and is generally used in for loops.
Function syntax
range(start, stop[, step])
Parameter description:
start: Counting starts from start. The default is to start from 0. For example, range(5) is equivalent to range(0, 5);
stop: counts to the end of stop, but does not include stop. For example: range (0, 5) is [0, 1, 2, 3, 4] without 5
step: step size, default is 1. For example: range(0, 5) is equivalent to range(0, 5, 1)
Example
>>>range(10) # 从 0 开始到 10 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(1, 11) # 从 1 开始到 11 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> range(0, 30, 5) # 步长为 5 [0, 5, 10, 15, 20, 25] >>> range(0, 10, 3) # 步长为 3 [0, 3, 6, 9] >>> range(0, -10, -1) # 负数 [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] >>> range(0) [] >>> range(1, 0) [] 以下是 range 在 for 中的使用,循环出runoob 的每个字母: >>>x = 'runoob' >>> for i in range(len(x)) : ... print(x[i]) ... r u n o o b >>> 在tensorflow python 3.6的环境下,range函数中实参必须为int型,否则报错 def load_dataset(data_dir, img_size): """img_files = os.listdir(data_dir) test_size = int(len(img_files)*0.2) test_indices = random.sample(range(len(img_files)),test_size) for i in range(len(img_files)): #img = scipy.misc.imread(data_dir+img_files[i]) if i in test_indices: test_set.append(data_dir+"/"+img_files[i]) else: train_set.append(data_dir+"/"+img_files[i]) return""" global train_set global test_set imgs = [] img_files = os.listdir(data_dir) for img in img_files: try: tmp= scipy.misc.imread(data_dir+"/"+img) x,y,z = tmp.shape coords_x = x // img_size coords_y = y // img_size #coords_y = y / img_size # coords_x = x / img_size #print (coords_x) coords = [ (q,r) for q in range(coords_x) for r in range(coords_y) ] for coord in coords: imgs.append((data_dir+"/"+img,coord)) except: print ("oops") test_size = min(10,int( len(imgs)*0.2)) random.shuffle(imgs) test_set = imgs[:test_size] train_set = imgs[test_size:][:200] return def get_batch(batch_size,original_size,shrunk_size): global batch_index """img_indices = random.sample(range(len(train_set)),batch_size) for i in range(len(img_indices)): index = img_indices[i] img = scipy.misc.imread(train_set[index]) if img.shape: img = crop_center(img,original_size,original_size) x_img = scipy.misc.imresize(img,(shrunk_size,shrunk_size)) x.append(x_img) y.append(img)""" max_counter = len(train_set)/batch_size counter = batch_index % max_counter #counter = tf.to_int32(batch_index % max_counter) window = [x for x in range(int(counter*batch_size),int((counter+1)*batch_size))] #window = [x for x in range(tf.to_int32(counter*batch_size),tf.to_int32((counter+1)*batch_size))] #window = [x for x in np.arange((counter*batch_size),((counter+1)*batch_size))] #a1=tf.cast(counter*batch_size,tf.int32) #a2=tf.cast((counter+1)*batch_size,tf.int32) #window = [x for x in range(a1,a2)] #window = [x for x in np.arange(a1,a2)] #win2 = tf.cast(window,tf.int32) #win2 = tf.to_int32(window) #win2 = tf.to_int64(window) imgs = [train_set[q] for q in window] x = [scipy.misc.imresize(get_image(q,original_size),(shrunk_size,shrunk_size)) for q in imgs]#scipy.misc.imread(q[0])[q[1][0]*original_size:(q[1][0]+1)*original_size,q[1][1]*original_size:(q[1][1]+1)*original_size].resize(shrunk_size,shrunk_size) for q in imgs] y = [get_image(q,original_size) for q in imgs]#scipy.misc.imread(q[0])[q[1][0]*original_size:(q[1][0]+1)*original_size,q[1][1]*original_size:(q[1][1]+1)*original_size] for q in imgs] batch_index = (batch_index+1)%max_counter
Related recommendations: "Python Tutorial》
The above is the detailed content of What does range mean in python?. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了Python怎么操作XML文件的相关问题,包括了XML基础概述,Python解析XML文件、写入XML文件、更新XML文件等内容,下面一起来看一下,希望对大家有帮助。

python的强大之处:1、对新手很友好,语法简单易学;2、代码强制缩进,结构清晰;3、有强大的第三方库支持,实现同样功能时,python的代码更简短;4、有着广泛的应用,如人工智能领域,网络数据抓取,web开发,机器学习等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use
