Finding Index for 0Hz on RF Spectrum

  • Thread starter Thread starter Erenjaeger
  • Start date Start date
  • Tags Tags
    Array Index
Click For Summary

Discussion Overview

The discussion revolves around finding the index corresponding to 0Hz in an RF spectrum versus frequency graph using Python. Participants explore methods for identifying this index within an array of frequency values, discussing various coding approaches and troubleshooting issues related to array handling.

Discussion Character

  • Homework-related
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • Some participants suggest using the numpy functions np.argmax or np.argmin to find the index of 0Hz, noting that np.argmin confirms the lowest value is 0 but does not directly provide the index.
  • One participant proposes iterating through the array to track the index and check for the value of 0, expressing uncertainty about how to implement this in code.
  • Another participant provides a code example demonstrating how to iterate through an array to find the index of 0, explaining the logic behind it.
  • There is a discussion about the variable names used in the code, with one participant mentioning issues when trying to run the provided code with their own array variable, "f2".
  • Participants clarify that since "f2" is already an array, there is no need to create a new array and suggest directly iterating over "f2".

Areas of Agreement / Disagreement

Participants generally agree on the approach of iterating through the array to find the index of 0, but there is no consensus on the specific implementation details or the issues encountered with the variable "f2".

Contextual Notes

Some participants express uncertainty about the error messages received when running the code, particularly regarding the handling of the "f2" variable and its structure as an array.

Erenjaeger
Messages
141
Reaction score
6

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
 
Physics news on Phys.org
Erenjaeger said:

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
in python 3 btw
 
Erenjaeger said:

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
Can't you just iterate through the array, keeping track of what index you're on, and see when the array value is 0?
 
Mark44 said:
Can't you just iterate through the array, keeping track of what index you're on, and see when the array value is 0?
Not sure how you would code that though I have to write a piece of code that does it, seems simple but I can't find any information on how to find the index where frequency is 0
 
Here's an example of what I'm talking about:
Python:
import array

arr0 = array.array('i', [3, 17, -1, 0, 5, 23, 18])
found = False

for i in range(len(arr0)):
   if arr0[i] == 0:
      found = True
      print("Found 0 at index ", i)
if found == False:
   print("Could not find 0")
If one of the values in the array happens to be zero, this code prints the corresponding index where it was found. If the array doesn't contain 0, the code displays a message that zero couldn't be found.
 
Mark44 said:
Here's an example of what I'm talking about:
Python:
import array

arr0 = array.array('i', [3, 17, -1, 0, 5, 23, 18])
found = False

for i in range(len(arr0)):
   if arr0[i] == 0:
      found = True
      print("Found 0 at index ", i)
if found == False:
   print("Could not find 0")
If one of the values in the array happens to be zero, this code prints the corresponding index where it was found. If the array doesn't contain 0, the code displays a message that zero couldn't be found.
The array is stored under a variable "f2" which is the x-axis and then "RF signal" which is the y axis, I tried running your code with f2 as the array but it didn't run. any idea why that might have been?
 
Can you show the code and the error message (or whatever was the result of running the code)?
 
mfb said:
Can you show the code and the error message (or whatever was the result of running the code)?
Yep! attached is the screen shot and also I printed the array "f2" so you could get an idea of what it consists of.
22883489_1503914236355013_1819086435_n.png
 

Attachments

  • 22883489_1503914236355013_1819086435_n.png
    22883489_1503914236355013_1819086435_n.png
    25 KB · Views: 830
Erenjaeger said:
Yep! attached is the screen shot and also I printed the array "f2" so you could get an idea of what it consists of.
View attachment 213956
I thought it might be taking f2 as a single element of the array rather than an array itself because that error message about length-1 arrays?
 
  • #10
What exactly do you expect "arr0=array.array('i',[f2])" to do? Why don't you iterate over f2 and get rid of arr0?
 
  • #11
In my example, I created the array named arr0. This array contains integers, which is the reason for 'i' in the statement arr0 = array.array('i', ...). Since you already have an array, f2, you don't need to create one. As @mfb suggests, just iterate over the array you have.
 
  • Like
Likes   Reactions: Erenjaeger

Similar threads

Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
20
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 24 ·
Replies
24
Views
3K