Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we represent the Python/numpy function "zeros_like" in Julia language

Tags:

julia

I am a bit new to Julia but I have some knowledge in Python. I am now learning Julia and I want to know how to represent the Python function "zeros_like" from Numpy in Julia. The python code is below:

import numpy as np
a = [3] #vector of one number
b = np.zeros_like(a)
like image 230
kkirui Avatar asked May 28 '19 12:05

kkirui


1 Answers

Base.zero function returns the zero element (the "additive identity element" in the doc) for the type of its input argument:

julia> a = [3]
1-element Array{Int64,1}:
 3

julia> zero(a)
1-element Array{Int64,1}:
 0

or

julia> zeros(Int, size(a))
1-element Array{Int64,1}:
 0
like image 50
Bill Avatar answered Nov 28 '22 08:11

Bill