Python Forum
What does this code fragment do?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What does this code fragment do?
#1
Given: brain_live_features is an array of ints ...

    live_features = brain_live_features + 2
    live_features = list(live_features)
    live_features = [0, 1] + live_features
    live_features = np.array(live_features).astype('int32')
My question is, what does this code do? When I type the first line into interactive python it gives me an error,
Error:
can only concatenate list (not "int") to list
My best guess is that we are adding the value 2 to each element of brain_live_features to adjust these indices before we prepend two new elements [0, 1].
Reply
#2
Seems to me that by "an array of ints" they are referring to a numpy array...
Reply
#3
Yes, I think you're right. If I say
blf = np.array( ...
then it seems to work. That seems to use the next line,
lf = list( lf )
to convert the np.array into a list so it can be concat'd.

Thank you.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020