Finding Index for 0Hz on RF Spectrum

  • Thread starter Thread starter Erenjaeger
  • Start date Start date
  • Tags Tags
    Array Index
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
10 replies · 2K views
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?
 
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: 842
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?
 
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