Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NotEth4n · Jan 06, 2015 at 08:43 AM · inputinputs

index out of range with length as for loop param

I am trying to loop through some inputs that are given to the function as an array of floats. I use a for loop to do so with the length of the array as the parameter. I don't know how but it seems that the index still somehow gets out of bounds...

 using UnityEngine;
 using System.Collections;
 
 public class Neuron {
     public float[] weights=new float[100];
     
     public float calculate(float[] inputs){
             float activation = 0f;
             for(int i=0;i<inputs.Length;i++){
                 activation+=inputs[i]*weights[i];
             }
             //bias
             activation += -1 * weights [weights.Length - 1];
             //Sigmoid
             return (1 / (1 + Mathf.Exp(-activation/0.5f)));
     }
     public void setWeights(float[] wts){
         weights = wts;
         Debug.Log(wts.Length);
     }
 }
 

With the error:

 IndexOutOfRangeException: Array index is out of range.
 Neuron.calculate (System.Single[] inputs) (at Assets/Neuron.cs:12)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image f4bo · Jan 06, 2015 at 09:53 AM 0
Share

how come the error points at line 12 but there is a comment there? anyway I bet 2 cents the error is at line 10 and the problem is the inputs are more that 100.

avatar image NotEth4n · Jan 06, 2015 at 07:48 PM 0
Share

Sorry, I took out a piece for testing but put in the previous error report. The error was now at Line 10. I found that @$$anonymous$$iraSensei was correct in that the weights was being set to an array of Length 0 in another class.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KiraSensei · Jan 06, 2015 at 08:44 AM

Are you sure "weights" is at least as long as "inputs" ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

New Input System: Can't set binding path anymore 2 Answers

what are the single joystick prefab's inputs for the input manager 1 Answer

Input System multiple actions on same keybind 0 Answers

Using DPad/Joystick in "new" InputSystem as digital rather than analog 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges