# Scale is not defined

**URL:** <https://discourse.julialang.org/t/scale-is-not-defined/88102>\
**Category:** General Usage\
**Created:** [October 1, 2022, 11:32pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102 "2022-10-01T23:32:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_shah2](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@m\_shah2](https://discourse.julialang.org/u/m_shah2)\
**Post date:** [October 1, 2022, 11:32pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/1 "2022-10-01T23:32:06Z")

</div>

UndefVarError: scale not defined

Stacktrace:  
[1] spectral\_embedding(W::SparseMatrixCSC{Float64, Int64}, nev::Int64)  
@ Main .\In[45]:10  
[2] top-level scope  
@ In[48]:1  
[3] eval  
@ .\boot.jl:368 [inlined]  
[4] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)  
@ Base .\loading.jl:1428

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [October 1, 2022, 11:45pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/2 "2022-10-01T23:45:28Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![m\_shah2](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@m\_shah2](https://discourse.julialang.org/u/m_shah2)\
**Post date:** [October 2, 2022, 5:59pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/3 "2022-10-02T17:59:43Z")

</div>

The “scale” should be a function of one of julia packages. I am new to julia and don’t know what package it belongs to. Can someone help me with that?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 2, 2022, 6:10pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/4 "2022-10-02T18:10:21Z")

</div>

> [@m\_shah2](#):
>
> The “scale” should be a function of one of julia packages. I am new to julia and don’t know what package it belongs to.

where did you get this piece of code to begin with

---

<div class="post-metadata">

**Author:** ![m\_shah2](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@m\_shah2](https://discourse.julialang.org/u/m_shah2)\
**Post date:** [October 2, 2022, 6:17pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/5 "2022-10-02T18:17:29Z")

</div>

// #Get embeddings, following algorithm of Ng et al., 2002.  
function spectral\_embedding(W::SparseMatrixCSC{Float64,Int64}, nev::Int64)  
d = sqrt.(vec(sum(W,dims = 1)));  
n = length(d);  
ai,aj,av = findnz(W);  
Ln = sparse(ai, aj, -av./((d[ai].\*d[aj])), n, n);  
Ln = Ln + 2 \* spzeros(n,n);  
(lams, V, \_) = MatrixNetworks.\_symeigs\_smallest\_arpack(Ln,nev,1e-12,300,d);  
s = vec(1 ./ sqrt.(sum(V.^2,dims = 2)));  
using LinearAlgebra, Statistics;  
return scale(s, V);  
end

The above code has return value where scale is used.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 2, 2022, 6:18pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/6 "2022-10-02T18:18:38Z")

</div>

> [@m\_shah2](#):
>
> The above code has return value where scale is used.

did someone just send you this code??? or this is something you found online

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 2, 2022, 6:19pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/7 "2022-10-02T18:19:00Z")

</div>

> [@m\_shah2](#):
>
> using LinearAlgebra, Statistics;

don’t do `using` inside a function this is not python

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 2, 2022, 6:31pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/8 "2022-10-02T18:31:42Z")

</div>

> [@jling](#):
>
> this is something you found online

[chonky url](https://notebooks.githubusercontent.com/view/ipynb?browser=chrome&color_mode=auto&commit=392a7c282439c92d5ac18ce529f90690143165b5&device=unknown&enc_url=68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f617262656e736f6e2f6869676865722d6f726465722d6f7267616e697a6174696f6e2d6a756c69612f333932613763323832343339633932643561633138636535323966393036393031343331363562352f72656163686162696c6974792d322d686f702d706174682e6970796e62&logged_in=false&nwo=arbenson%2Fhigher-order-organization-julia&path=reachability-2-hop-path.ipynb&platform=android&repository_id=60560314&repository_type=Repository&version=99) 🤓

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 2, 2022, 6:37pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/9 "2022-10-02T18:37:27Z")

</div>

what’s in `include("higher_order_packages.jl")`

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 2, 2022, 6:40pm UTC](https://discourse.julialang.org/t/scale-is-not-defined/88102/10 "2022-10-02T18:40:01Z")

</div>

`scale` was a function in Base Julia up to version 0.4, before being deprecated in Julia 0.5 in favor of plain or broadcasted multiplication. This was the docstring in Julia 0.4:

```julia
  scale(A, b)
  scale(b, A)

  Scale an array A by a scalar b, returning a new array.

  If A is a matrix and b is a vector, then scale(A,b) scales each column i of A by b[i]
  (similar to A*diagm(b)), while scale(b,A) scales each row i of A by b[i] (similar to
  diagm(b)*A), returning a new array.

```
