Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

1d array to one hot

>>> a = np.array([1, 0, 3])
>>> b = np.zeros((a.size, a.max()+1))
>>> b[np.arange(a.size),a] = 1
>>> b
array([[ 0.,  1.,  0.,  0.],
       [ 1.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  1.]])
Comment

1d array to one hot


>>> a = np.array([1, 0, 3])
>>> b = np.zeros((a.size, a.max()+1))
>>> b[np.arange(a.size),a] = 1
>>> b
array([[ 0.,  1.,  0.,  0.],
       [ 1.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  1.]])

Comment

PREVIOUS NEXT
Code Example
Python :: Python program to draw star 
Python :: requests.packages.urllib3.util.retry could not be resolved from source 
Python :: how to remove tkinter icon 
Python :: separate a string in python 
Python :: seaborn correlation heatmap 
Python :: check all values in dictionary python 
Python :: discord.py get channel id by channel name 
Python :: django dockerfile multistage 
Python :: how to use global variable in python 
Python :: pandas profile report python 
Python :: pyside 
Python :: python - change the bin size of an histogram+ 
Python :: python how to remove commas from string 
Python :: how to sort a dictionary using pprint module in python 
Python :: count elements in list 
Python :: size of the query process in python BigQuery 
Python :: best python ide for ubuntu 
Python :: how to convert the date column from string to a particular format in python 
Python :: rotate image python 
Python :: import numpy financial python 
Python :: del all variables python 
Python :: print dictionary of list 
Python :: heroku python buildpack 
Python :: how to define the name of your tkinter window 
Python :: how to get scrapy output file in csv 
Python :: import csrf_exempt django 
Python :: reverse an array pyton 
Python :: how to get the ip address of laptop with python 
Python :: python list all methods of a class 
Python :: one line if statement no else 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =