javadl4jnd4j

Cannot resolve symbol 'linspace' in ND4j


I'm pretty new in Java. I would like to initiate an array using Nd4j library INDArray x = new Nd4j.linspace(0, 1, 100);, doing something like x = np.linspace(0, 1, 100) in Python. And I ran into an error

java: cannot find symbol

symbol: class linspace location: class

org.nd4j.linalg.factory.Nd4j

Although my Nd4j was well installed adding the following in pom.xml, and my IDE IntelliJ can detect ND4j class.

    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-api</artifactId>
        <version>1.0.0-M2</version>
    </dependency>

Am I missing or misunderstood anything? Thanks for your kind help


Solution

  • The problem is:

    INDArray x = new Nd4j.linspace(0, 1, 100);
    

    Because you use new, Java tries to create a class called Nd4j.linspace, which does not exist (as indicated by the "cannot find symbol, symbol: class linspace"). The class Nd4j does have a method linspace. To fix this, remove new so you call the method:

    INDArray x = Nd4j.linspace(0, 1, 100);