Many residents of high-crime neighborhoods take a more nuanced position on the NYPD’s stop-and-frisk practices than the politicians and advocates who purport to represent them.

“I’m 50-50 on it,” says South Bronx resident Daniel Valdez, 32. He was stopped for the first time in his life near his Melrose Avenue home several months ago at 7:30 p.m. “Three guys had me up against the wall, they ran my ID and emptied my pockets. I was treated like a criminal.”

Yet he acknowledges that the stops “do serve a purpose. I have a bad neighborhood. There’s needles on the ground and drug transactions going on at the corner.”

Last month 16-year-old Moises Lora was beaten to death by rival gang members a few blocks from where Valdez lives. Several dozen spectators watched without intervening. Across the street, a 26-year-old man was fatally shot the day before.

Local gangs keep residents under the thrall of fear. “The kids stay in jail in their own project,” Keisha Graham, 40, told a local paper. “We’re paying taxes for what? I don’t pay taxes for kids to keep getting buried.”

It is this mindless violence that leads NYPD commanders to target communities such as Valdez’s for assertive patrol. Race has nothing to do with it.

If the Bronx’s 42nd Precinct had the same rate of murders and shootings as Manhattan’s 19th Precinct — i.e., virtually zero — police activity there would be equally inconspicuous.

Valdez thinks the cops should have known he was on his way to the store. But residents of high-crime neighborhoods often have unrealistic expectations of the police’s ability to distinguish innocents from criminals without their assistance, says Temple University criminologist Jerry Ratcliffe.

Damon Dobbs, the director of a Harlem youth program, took along two boys from the program to Manhattan Borough President Scott Stringer’s “anti-crime” (read: anti-stop) rally earlier this month. Dobbs has never been stopped by the police, though he lives in a high-crime part of upper Harlem, nor had one of the boys with him, 15-year-old Joshua.

There are “pat and frisks that aren’t warranted,” Dobbs says, but the main problem is communication and training. The police use stops to try to “maintain control” in troubled neighborhoods, especially where youth are congregating, he observes astutely. They “speak with authority and the kids resist that. They could have a valid reason for stopping someone and it gets lost” in the interaction.

But while some officers need to do a better job communicating, local residents need to take accountability for crime, Dobbs says. “If they say nothing or do nothing,” the police are going to step in.

Dobbs’ other charge, 16-year-old Jamal, had been stopped — most recently two weeks before, while walking with some friends in Harlem at around 11 p.m. “I can’t say it was polite; I was mad,” he says. Was that stop justified? It’s impossible to say for sure without knowing more — but some of Jamal’s gangbanger friends were shot and killed a year ago, and he himself has an arrest record.

What is certain is that it is the lethal crime that Jamal’s friends are involved in, not their race, that led officers to be on the lookout for suspicious behavior in his neighborhood. If Jamal’s parents and those of his gangbanger friends exercised more control over their children, the cops wouldn’t have to.

And had the criminals who shot Jamal’s friends been frisked while they were carrying their gun, his friends might be alive today.

At the rally, I also met Cid, 58, white and a former junkie. He was searched two weeks before when sitting on his stoop in East Harlem. “There was no justification for it,” he says. Actually, the police were responding to a call reporting a strange person in the neighborhood: Had they not questioned him, they’d have been ignoring a resident’s valuable efforts to maintain order.

The stop-and-frisk program should not be immune from reevaluation, and Commissioner Ray Kelly last week announced reasonable new oversight measures. Determining whether officers have retained their discretion in deciding how to respond to low-level offenses is vital.

The department is also experimenting in Brownsville with the “Ceasefire” call-in method touted by NYPD critics — even though the cities using “Ceasefire,” such as Boston and High Point, NC, have much higher crime rates than New York.

But while the stop program, like all NYPD tactics, should be — and is — constantly reassessed, the effort to portray stops as a racist assault on minorities is poisonous and irresponsible. To date, no other government initiative has come close to saving as many lives and improving the quality of life in poor communities as the NYPD’s proactive policing.

Heather Mac Donald is a contributing editor at City Journal and author of “Are Cops Racist?”