Python> List> partitions = [0] * len (all_filepaths) / partitions [: test_set_size] = [1] * After creating a list with test_set_size> 0, set the front part to 1.

Operating environment


GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.

Learning the Deep Learning framework TensorFlow.

https://ischlag.github.io/2016/06/19/tensorflow-input-pipeline-example/

The following description of "Lets Partition the Data" did not understand at first glance above.

# create a partition vector
partitions = [0] * len(all_filepaths)
partitions[:test_set_size] = [1] * test_set_size

I've tried.

list_001.py


all_filepaths = [ "AAA/BBB/c.csv", "AAA/BBB/d.csv", "AAA/BBB/e.csv" ]

test_set_size = 5

partitions = [0] * len(all_filepaths)
print(partitions)
partitions[:test_set_size] = [1] * test_set_size
print(partitions)
$ python list_001.py 
[0, 0, 0]
[1, 1, 1, 1, 1]

[0] * 5 produces a list with 5 0 elements.

What I didn't understand was that I made a list with [0] and then changed it to a list with [1].

It seems that len (all_filepaths) is filled with 0s and only some of them are set to 1. I found that I set the item of all_filepaths to 20 and so on.

Recommended Posts

Python> List> partitions = [0] * len (all_filepaths) / partitions [: test_set_size] = [1] * After creating a list with test_set_size> 0, set the front part to 1.
[Introduction to Python] How to sort the contents of a list efficiently with list sort
A python amateur tries to summarize the list ②
How to get a list of files in the same directory with python
[Python] Creating a tool that can list, select, and execute python files with tkinter & about the part that got caught
How to identify the element with the smallest number of characters in a Python list?
After hitting the Qiita API with Python to get a list of articles for beginners, we will visit the god articles
How to shuffle a part of a Python list (at random.shuffle)
Probably the easiest way to create a pdf with Python3
The first step to creating a serverless application with Zappa
[Part.2] Crawling with Python! Click the web page to move!
Recursively get the Excel list in a specific folder with python and write it to Excel.
How to get the last (last) value in a list in Python
[Python] The first step to making a game with Pyxel
Extract the value closest to a value from a Python list element
[Introduction to Python] How to split a character string with the split function
I tried to create a list of prime numbers with python
I wanted to solve the ABC164 A ~ D problem with Python
Pass a list by reference from Python to C ++ with pybind11
How to send a request to the DMM (FANZA) API with python
[Python] A program that rotates the contents of the list to the left
Convert list to DataFrame with python
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
[Introduction to Python] What is the difference between a list and a tuple?
How to crop the lower right part of the image with Python OpenCV
[Introduction to Udemy Python3 + Application] 47. Process the dictionary with a for statement
[Python] Explains how to use the range function with a concrete example
I was addicted to creating a Python venv environment with VS Code
Send mail with mailx to a dummy SMTP server set up with python.
Deb package development with Git: (Part 1) Creating a stray package with the minimum configuration
[Python] How to set the (client) window size inside the browser with Selenium
Receive a list of the results of parallel processing in Python with starmap
[Introduction to Python] How to write a character string with the format function
Try to solve a set problem of high school math with Python
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
Creating a simple PowerPoint file with Python
[Python] Set the graph range with matplotlib
[Python] How to convert a 2D list to a 1D list
Search the maze with the python A * algorithm
Python amateurs try to summarize the list ①
[Part1] Scraping with Python → Organize to csv!
Introduction to AI creation with Python! Part 2 I tried to predict the house price in Boston with a neural network
The road to compiling to Python 3 with Thrift
Try to solve the traveling salesman problem with a genetic algorithm (Python code)
[Python] Created a class to play sin waves in the background with pyaudio
[Python] Solution to the problem that elements are linked when copying a list
Calculate the optimal solution to set a world record for decathlon with scipy.optimize
Python script to get a list of input examples for the AtCoder contest
[Introduction to Python] How to get the index of data with a for statement
Introducing the book "Creating a profitable AI with Python" that allows you to learn machine learning in the shortest course
[Python] List Comprehension Various ways to create a list
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
[Python] Get the files in a folder with Python
Tweet the weather forecast with a bot Part 2
How to clear tuples in a list (Python)
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
Try to draw a life curve with python
Specify the Python executable to use with virtualenv
I want to make a game with Python